Batch-redirect external-file links?

Dear folks,

I’m preparing a sprawling wiki for 100% offline use (for locked-down laptops with no internet).

I had pretty much completed a conversion from mostly-dropbox-hosted files to a set of relative links — with all the supporting files in the same folder as the wiki itself.

Alas, I’ve just learned I need to have only the html document at the root level, with all images and other resources tucked within a subfolder.

Does anyone have any tips about whether/how external links (jpg, png, webp, pdf) might be efficiently converted so as to add the /images/ directory at the beginning of each?

Alas, this time around there’s no single string to search for. Perhaps there’s a regexp solution… but it’s not simple, since these references can be in a number of fields, and may or may not appear in [img[alias| framing and such.

Any hints toward a not-terribly-tedious approach would be welcome!

I wonder if there is a way to leverage the relink plugin or at least the filter operators that come with it?

Although I belive as a rule the html file can be set to reference a subfolder for resources, this can be introduced by the appropriate raw tag and you may not need to make any changes in the wiki tiddlers.

  • This is I belive comonly done for websites and specificaly the images folder.

Surely you need only target external images? _canonical_uri and then only those without images/ folder mentioned and append it?

Thanks for the speedy reply. This sounds promising, but I’m afraid I don’t follow.

Websites, which are HTML files, and tiddlywiki is a website, commonly have image folders, rather than encode the path to the only folder that contains images (on every image), they allow that folder to be specified and all attempts to load an image are found there in. TiddlyWiki is just a website, and you can add “code” to the html file via one of the 6 the raw tags in tiddlywiki, although I do not know from memory I am confident you can set the images folder globaly for your wiki.

1 Like

This would be a good argument for always using _canonical_uri objects.

I think I would consider opening the file with a good file editor and using the dreaded regular expression search and replace en masse that way.


Alternatively, using Wiki text.

Get a list of all the files in your directory. Create a tiddler list of them as titles (e.g. using [[ ]] ) . Write a routine that goes through each item and uses it as part of a matching/replacing routine. See other discussions here on the regular expression (regexps) routine that can do this in one go. Or use the string/replace routine that is part of the core.

The main problem would be if you have image names that could be mistaken for ordinary words. In that case, manually fix those items.

see HTML base tag

Try this:

Create a tiddler (e.g., “SetBaseURL”), tagged with $:/tags/RawMarkup, containing:

<base href="images/">

You will need to save-and-reload for the RawMarkup to be added to the <head>...</head> section of the file.

-e

3 Likes

Perfect! @EricShulman and @TW_Tones, you both understood this html trick that I had never had occasion to use. Saves me hours of digging through all the variant places where these file references were in place!

Many thanks.

1 Like