How to render index.html through customized publish filter?

Please help, I use nodejs tiddlywiki and I want to through a customized publish filter to generate index.html so I can publish my tiddlers which be tagged with “publish”.
I konw we have a render command to save index.html, I looked it in tiddlywiki.info file, The only one solution I can thought is to modify the content of $:/plugins/tiddlywiki/tiddlyweb/save/offline file, It seems including some filters to choose which tidddlers to be rendered, So do I have any other convenient way to do this such as through command line? Please.

1 Like

If you have a closer look at: TiddlyWiki5/editions/tw5.com/tiddlywiki.info at eeeb9f97a9b517f5ed76267bb50d4d141c72c251 · Jermolene/TiddlyWiki5 · GitHub you will see the filter, that defines the index.html is $:/core/save/all

It can be found at: tiddlywiki.com $:/core/save/all

\import [subfilter{$:/core/config/GlobalImportFilter}]
\define saveTiddlerFilter()
[is[tiddler]] -[prefix[$:/state/popup/]] -[prefix[$:/temp/]] -[prefix[$:/HistoryList]] -[status[pending]plugin-type[import]] -[[$:/boot/boot.css]] -[is[system]type[application/javascript]library[yes]] -[[$:/boot/boot.js]] -[[$:/boot/bootprefix.js]] +[sort[title]] $(publishFilter)$
\end
{{$:/core/templates/tiddlywiki5.html}}
  • Create a new configuration tiddler in your wiki eg: $:/config/myCustomWiki
  • Instead of [is[tiddler]] you can use [tag[publish]]
  • You need to keep the rest of the parameters.

Then you can create a new section in your tiddlywiki.info file eg:

		"custom": [
			"--savetiddlers","[tag[external-image]]","images",
			"--render","[tag[external-text]]","[encodeuricomponent[]addprefix[text/]addsuffix[.tid]]","text/plain","$:/core/templates/tid-tiddler",
			"--setfield","[tag[external-image]]","_canonical_uri","$:/core/templates/canonical-uri-external-image","text/plain",
			"--setfield","[tag[external-text]]","_canonical_uri","$:/core/templates/canonical-uri-external-text","text/plain",
			"--setfield","[tag[external-image]] [tag[external-text]]","text","","text/plain",
			"--render","$:/config/myCustomWiki","custom.html","text/plain"],
  • See the name custom: [
  • and the last line "--render","$:/config/myCustomWiki","custom.html","text/plain"],
  • If you don’t have any _canonical_uri tiddlers, you can remove the first 5 lines completely and only keep the --render command.

Build it

cd /to/your/edition
tiddlywiki . --build custom

This command will create a new output directory and save your wiki there

Hope that helps
-mario

1 Like

Hi, sir, thanks for your specific explanation, Of course you are right, but according to the SavingMechanism of tiddlywiki,

and it has follow content:

\import [subfilter{$:/core/config/GlobalImportFilter}]
\define saveTiddlerFilter()
[is[tiddler]] -[[$:/boot/boot.css]] -[prefix[$:/HistoryList]] -[status[pending]plugin-type[import]] -[type[application/javascript]library[yes]] -[[$:/boot/boot.js]] -[[$:/boot/bootprefix.js]] -[[$:/plugins/tiddlywiki/filesystem]] -[[$:/plugins/tiddlywiki/tiddlyweb]] -[prefix[$:/temp/]] +[sort[title]] $(publishFilter)$
\end
{{$:/core/templates/tiddlywiki5.html}}

I notice that there is a $(publishFilter)$ after all filters, I don’t know the usage of this grammar in tiddlywiki, but I guess this might be a global variable or macro?

This might be a convenient way to customize publish filters through defining the value of $(publishFilter)$. Do you know this kind of grammar? and how can I define its value whether through command or config tiddler? thank you

1 Like

You can certainly modify the publish filter! There’s a bit of explanation for this $(syntax)$ here:

https://tiddlywiki.com/#Substituted%20Attribute%20Values

I’ve modified the publish filter in one of my working wikis here: Quick demo — showcasing…

… for the purpose of not saving tiddlers with a certain field value. Follow up if I’m not following the point of your question. (I’m not a node.js user, so anything specific to that configuration will be out of my grasp, but others here may chime in.)

Hi @uzvg the simplest way to accomplish that is as follows.

tiddlywiki editions/tw5.com --render \
  '.' \
  'index.html' \
  'text/plain' \
  '$:/core/save/all' \
  'publishFilter' \
  '-[is[tiddler]!is[system]] [tag[HelloThere]]'

(I’ve used single quotes for macOS/Linux, I think you may need to use double quotes if you’re using Windows).

The example above works by excluding all non-system tiddlers and then re-including the tiddlers with the tag. That means that it will include any system tiddlers present in the wiki, regardless of whether they carry the tag.

A lower level alternative provides precise control over which tiddlers are included:

tiddlywiki editions/tw5.com --render \
  '.' \
  'index.html' \
  'text/plain' \
  '$:/core/templates/tiddlywiki5.html' \
  'saveTiddlerFilter' \
  '$:/core $:/library/sjcl.js $:/themes/tiddlywiki/snowwhite $:/themes/tiddlywiki/vanilla [tag[HelloThere]]'

In this version, every tiddler to be included in the wiki must be explicitly listed. $:/core $:/library/sjcl.js $:/themes/tiddlywiki/snowwhite $:/themes/tiddlywiki/vanilla is the minimum list of system tiddlers for a working wiki. If you want to include any plugins or configuration tiddlers in the wiki then you will need to explicitly add them here.

1 Like

I am too stupid for this. I tried all the mentioned command on my linux box where I run tiddlywiki 5.3.5 and all i get is either garbage or 0 byte files.

Running on nodejs, all I want is a copy of my wiki but with a filtered tiddler list. Some filters do contain private information, and that is something I do not want to make public.

I can’t figure it out. Maybe some plugins are the problem? I don’t know. Custom Fonts?

If someone could really explain this with a fresh wiki, like a step by step thing, that would be wonderful.

Things I tried:

I installed nodejs on my MacBook and created a new tiddlywiki from scratch. I then created a bunch of tiddlers, with some tags like ‘DailyNote’ and ‘Meta’ and ‘JournalEntry’. I then executed the command from Jeremy Ruston but the result was not good. The created index.html file does not contain any CSS, neither does it contain any tags.

I am a bit frustrated to be honest. I really like tiddlywiki a lot, and I use it at work for almost everything. But there, it is for internal things only, and I never ever had the need for exporting it or transfer a limited, reduced version to a colleague.

It would be remarkable if the build command could take care of this, but I cannot figure it out. Every time I change it, the filter that works inside tiddlywiki tiddler,seems not to work on the command. It feels so frustrating that a simple thing like this, is quite challanging and complicated.

Perhaps another approach
h
If you use the innerwiki plugin you can choose what tiddlers appear in the innerwiki in this case perhaps everything except the private things. Inside the inner wiki make download button to then capture the revised wiki to save as a file.

  • You can use the innerwiki to see what it will look like to the user and that you did not break anything before saving.

[Edited] See here https://takeaway-wikis.tiddlyhost.com/ where I am using the innerwiki plugin for wiki generation

Hi TW_Tones,

Thank you for your answer. Would it be possible to automate this process of saving the innerwiki_via command line? And how do I include data and tiddlers from the current one. I tried the filter and some other things, but even looking at your examples, I could not find the hint or the missing info on how to include a filtered list of my data.

[Update]

I managed to better understand how this innerwiki syntax works. I was not seeing the tiddlers, as normally, I would have them opened as default tiddlers.

But I came up with this now:

<$innerwiki>
	<$data title="HelloThere" text="This tiddler is inside a wiki"/>
    <$data $filter="[!is[system]!tag[PRIVATE]]" />
    <$data title="$:/DefaultTiddlers" text="[[index2]]"/>
</innerwiki>

Now I weed a way to automate the export from CLI to have this rendered and saved to a different location. That would be wonderful.

I cannot figure out the --render command, as it sometimes produces things, and sometimes not. I do not need to render the things as screenshots, though.

I tried the examples and the render command

tiddlywiki . --render '[[innerwiki]]' "examples.html" --build index

but the result looks like a big screenshot? An Image src that cannot be displayed and the whoe wiki text is somehow part of the SVG container.

I don’t use the command line for tiddlywiki so cant help, but I also ask if there is a way interactively why use the command line?, however if you use the command line you will most likely build the wiki direct, without inner wiki.