Redirecting on load by altering the fragment identifier

I have a website I wrote that I’m thinking of moving to TiddlyWiki. Everything seems easy to port over except that the URLs for various pages have been published in places I cannot change. (Some are in print media.) So I’m wondering, is there some facility that would let me interrupt startup and either
redirect to the proper URL or load the tiddler after a slight fiddle to the fragment (hash) string?

The bulk of the current entries look like this:

http://example.com/#/2023-07-26

But there are others like

http://example.com/#/pages/about
http://example.com/#/search/foo+bar
http://example.com/#/series/My+Series+Title
http://example.com/#/person/Jane+Doe
http://example.com/#/topic/Something

I believe all current URLs can be redirected by changing + to %20 and replacing the initial #/ with just #. I can code that easily. But I don’t know how and where to add the code that does it. I’m comfortable with JS, and there’s part of me that would just go in and hack the core for a one-off wiki, but I’d like to know if there are already hooks for this sort of behavior. Are there? Are they documented somewhere?

(I have no problem naming later works to avoid collision by never starting a tiddler name with a /.)

Is this behavior available? Can I hook into the loading behavior to add URL fragment conversion behavior?


(Mostly irrelevant) Background

For those who want to know, I am one of those gadflies who writes often to my local weekly newspaper, usually about national political topics, often in response to other such gadflies. At some point, wanting to play around with various bits of web development I’d been away from, I decided to publish these letters online. I’ve tweaked it over the last few years, fixing problems, etc. But I would love to stop some of the maintenance, and at least consider converting it to TW. It’s stored at GitHub - CrossEye/letters and hosted at http://letters.sauyet.com/. (Please avoid if you’re allergic to progressive political ideas or discussions of American politics/governance.)

1 Like

You could write startup actions that parse the URL and open the appropriate tiddler: https://tiddlywiki.com/#StartupActions

Look at the shadow tiddlers prefixed $:/info/url for wikitext access to the URL.

Thank you. And if I wanted to do this in JS, would it just be module-type: startup? There must be some way to put this in the proper spot in the startup sequence. Is that exports.after? And if so, is there a list of the existing sequence for the core modules?

The startup story module handles the hash and tiddler loading so the quick and dirty way would be to modify that module.

You could try writing a startup module that loads before startup/story.js and modifies the location hash, and then allow startup/story.js to do its usual handling.

exports.name= "custom-startup";
exports.before = ["story"];
exports.after = ["load-modules"];

A pluggable wikitext based mechanism for replacing the default startup handling would be very desirable from my perspective.

That sounds perfect. I will try that (in the next few days if I find time, or after my two-week vacation if not.) Thank you very much for your (very quick!) help.

1 Like

TiddlyWiki already supports handling of URL fragments by interpreting anything after the hash mark (#) as a tiddler title, and then automatically displaying that tiddler in the StoryRiver upon startup (bypassing the DefaultTiddlers filter specified in the $:/ControlPanel).

For example, if you follow this link:

https://tiddlytools.com/#TiddlyTools/About

It will load https://tiddlytools.com AND automatically show the “TiddlyTools/About” tiddler in the StoryRiver.

Thus, if you host a TiddlyWiki file at http://letters.sauyet.com/index.html and port the content of an existing letter (e.g. http://letters.sauyet.com/#/2009-08-23/) to a tiddler with a title of “/2009-08-23”, then it should just work, without having to write any custom JS code or create a tiddler tagged with $:/tags/StartupAction.

-e

Right. I should have mentioned this as an option. I’d rather not keep that as a permanent format for my titles once I’m in TW. I’d rather just write 2009-08-23, or better yet, an actual meaningful title like Constitutional Law.

Thank you, though, for bringing it up. I will consider it, as it is a much simpler conversion.

If you want to keep your tiddlers to maintain links but have them take one new titles and new links I have a set of tools that can help. Just ask

Thank you very much for the offer. A lot of this is meant as a learning exercise for me. Even if I get it working, I’m not sure whether or not I’ll use it, but I would like to try this myself based on the suggestions already supplied.

So, for now, thank you anyway. Later, who knows? I may be asking for them for this or another project.

Thank you for your willingness to help.