Determine whether the current render is part of a static site

In a template (or for that matter anywhere in wikitext), is there a way to determine whether we’re currently generating a static site? I would like to hide some features in the static site that don’t function correctly without JavaScript. I’m envisioning something like:

<$list filter="[<isGeneratingStaticSite>!match[yes]]" variable=_>
   ... insert stuff to show only in the native version here ...
</$list>

Worst case I guess I could make a copy of the whole wiki and change a tiddler before rendering, but that seems stupid.

How are you rendering the static site? Are you using the nodejs --render command?

Currently using the default “static” build rule in the tiddlywiki.info, which uses --rendertiddler and --rendertiddlers:

        "static": [
            "--rendertiddler",
            "$:/core/templates/static.template.html",
            "static.html",
            "text/plain",
            "--rendertiddler",
            "$:/core/templates/alltiddlers.template.html",
            "alltiddlers.html",
            "text/plain",
            "--rendertiddlers",
            "[all[tiddlers+shadows]!is[system]] -[[TakeAway Reviewer]]",
            "$:/core/templates/static.tiddler.html",
            "static",
            "text/plain",
            "--rendertiddler",
            "$:/core/templates/static.template.css",
            "static/static.css",
            "text/plain"
        ]

No particular attachment to this method though, anything I can call from a Makefile is fair game.

I haven’t worked much with static site rendering but the --rendertiddler and –rendertiddlers commands are deprecated in favour of --render
See: TiddlyWiki — a non-linear personal web notebook

You can pass an optional variable like isGeneratingStaticSite and set it to yes.

Thanks Saq, it looks like this will work. It was not as straightforward as I hoped to convert --rendertiddlers to --render…if --rendertiddlers is deprecated, the default tiddlywiki.info should be changed! I see there’s an open issue about this:

I ended up needing:

            "--render",
            "MY_TIDDLER_FILTER",
            "[encodeuri[]addprefix[static/]addsuffix[.html]]",
            "text/plain",
            "$:/core/templates/static.tiddler.html",
            "renderingStatic",
            "yes",

Note especially the encodeuri[]in the filename filter – the links within the static output are created as double-encoded, so if you don’t explicitly encode the filenames, the links point to the wrong place.

Also, you have to use text/plain, rather than text/html as you would expect, or it tries to create HTML out of HTML, resulting in a garbled page with a bunch of nested <code> tags containing HTML.

1 Like

Completely agreed. It just requires someone familiar enough with the command to have the time to prepare a PR.

Yes, we ought to establish a convention for a standard variable like tv-static-rendering that is set to yes when rendering static output. We would set the variable in the core static templates.

You could use the single file tiddlywiki and play with the existing templates for exporting. In there you could add logic that shows or hides content according to some conditions eg your variable isGeneratingStaticSite and list as demonstrated. @sobjornstad