Use a js-library to convert mixed lunar & solar Gregorian dates into standard Gregorian dates

I would like to create <a> element to open a tiddler in story river as the same behaviour of <$link /> widget.

This is my current method

var li = document.createElement('li');
var opts = {
    "class": "tc-tiddlylink tc-tiddlylink-resolves",
     text: title ,
     attributes: { href: '#'+ title }
};
var tidlink = $tw.utils.domMaker("a", opts);
li.appendChild(tidlink);

It does create a link. However, this link will open tiddler at the top of story river (my setup is bottom), and also modify the URL with anchor link to tiddler.

How should I create link same as <$link /> widget using js?

I don’t understand why?

If you use the link widget this is in fact what it generates and A record to the tiddler in the current wiki.

If this is because you are trying to encode it in a bigger solution you are developing in Javascript you should ask this in the developer forum, not in the general discussion forum.

  • This could mislead people into thinking it is necessary to use JavaScript, it is not.
  • Use the browser inspect to see what the link widget does produce to make sure you comply with the standards.

There is a tiddlywiki default as to where to open a tiddler which works at least for standard navigation links see Control Panel > Settings > tiddlywiki > Tiddler Opening Behaviour

However you can also add and remove items from $:/StoryList list field, and do so in the order you wish to open a tiddler whereever you want in the story.

  • “TiddlyWiki Script” is already designed to cater for this kind or manipulation so in most cases one should not revert to JavaScript, unless necessary.
  • If you use the standard approaches your solutions will be more interoperable with other tiddlywiki solutions and plugins. By coding in JavaScript you should be sticking with the core development standards and if you do not you risk making incompatible solutions, especially after a core upgrade.

It would be interesting to know why you want to use javascript to create list elements?
Can you be a bit more specific, using plain text, what you try to achieve?

Usually it’s not needed to do it that way. Your solution does no work, because the list-widget also establishes an event-handler, that sends a “navigate to” signal to the navigator-widget if a link is clicked. The navigator widget then takes care to open the tiddler in the right place according to global settings.

The HREF attribute of the anchor element that you create will activate default browser behaviour and writes a new URL into the browser address bar. Changing the browser address bar will activate a completely different mechanism in the core. That’s the reason, why it does not work.

Thanks for your reply. Sorry for the misleading information.

I want to create a list or calendar to display anniversary based on data structure in Memory Keeper, i.e. anniversary events are tagged with event and anniversary, and have a field date. Until here I know how to create a list with only wikiText.

My challenge is that date are mixed with lunar and solar/gregorian dates. So I add a new field date-type to indicate whether it is a lunar date. Then I have to call a js library to convert lunar month and day in the current or previous years (if month is November or December) into Gregorian date in current year and sort by month and day in new Gregorian dates.

I have the js to convert date and sorting, but have trouble to create a element to link to tiddler.

It is better to use wikitext to create the display elements. It is possible to return a (sorted) list of tiddler titles from a javascript macro and pass that to the list widget:

<$list filter=<<myListOfTiddlers>>>
{{||someformating}}
</$list>

Creating a widget would be the best way, because widgets can handle their updates by themselves, but they are more complex to create.

I think buggyj is on the way here. It would be possible to create a macro, that does the work and writes the “converted” information back to the tiddlers or tw-variables

IMO this workflow is a bit hacky, but js-macros are easier to create.

  • The info should only be written once.
  • So existing tiddlers have to be read.
  • The date calculation should be executed.
    • IMO This should optional. If you know that you need to recalculate it.
  • Compare the new result with the existing value in the tiddler and
    • only update if there is a difference.

This workflow should avoid unnecessary UI updates.

Whenever a tiddler is modified in the tiddler store TW automatically does a refresh for all UI elements that are rendered and have been changed.

Then your macro can create a TitleList as an output. JS-macros can only return text-strings.

If that TitleList will be passed to a list-widget as buggyj suggested you should be good to go. – At least I think so.

1 Like

I did change the thread title to a more generic one, which IMO is a better fit, what actually should be achieved.

@Zheng_Bangyou If you think the title should be different you can change it again. If you cannot change it. Just tell me the new title, so I’ll change it again

1 Like

so a basic macro to return a list of tiddler titles is

exports.params = [
	{name: "filter"}
];

// Static method to bracket a string with double square brackets if it contains a space
	function encodeTiddlyLink(title)
	{
		return title.indexOf(" ") == -1 ? title : "[[" + title + "]]";
	};


	function encodeTiddlyLinkList(list)
	{
		if(list) {
			var t,results = [];
			for(t=0; t<list.length; t++)
				results.push(encodeTiddlyLink(list[t]));
			return results.join(" ");
		} else {
			return "";
		}
	};

exports.name ="runfilter";
exports.run = function(filter) 
{
return encodeTiddlyLinkList($tw.wiki.filterTiddlers(filter));
};
1 Like

I would very much like to have support for alternate calendars in TiddlyWiki as a plugin. I think we’d need a few tweaks to the core too. I had a quick look for relevant JavaScript libraries and found [one that seems hopeful](GitHub - LIjiAngChen8/chinese-lunar: ChineseLunar is a lightweight (3 kB) JavaScript library for converting lunar calendar dates, boasting a powerful API and extensibility. handles lunar calendar dates), but there may well be more.

@linonetwo @oeyoews @oflg might this be something that there would be interest in in the broader Chinese TiddlyWiki community?

Thanks for all your help. @jeremyruston Very appreciate it if tiddlywiki can support a plugin for calendars.

After searching and testing lots of library, I finally use shiren calendar which uses MIT license. Other similar libraries don’t have license file or more restriction license, or I don’t know how to use them.

With suggestion from this community, I can produce an anniversary table to list all people, solar dates, lunar dates and days until next anniversary.

image

This feature should be enough for my current target.

Happy to share after adding some documentation if anyone is interesting.

I haven’t use any lunar year related things. My GitHub - tiddly-gittly/tiddlywiki-calendar: Widget and Page Layout displaying tiddlers on calendar and agenda, based on created, modified, startDate and endDate fields. only support simple cases.

@Zheng_Bangyou To navigate using JS, see this example How to navigate to a tiddler (when out of default layout widget tree) · Jermolene/TiddlyWiki5 · Discussion #8123 · GitHub

1 Like

Thanks @Zheng_Bangyou @linonetwo. I think a Chinese speaker might need to take a lead on this; the documentation and usage of the library you mention is difficult for me. But I’d be very happy to make the required core modifications.