I’m trying to dynamically generate a number of single-file wikis from within a JS application. They will each have a little over 32K (very small) tiddlers. I’m able to quickly generate the tiddlers. But trying to use them to build a wiki is more difficult than I would hope. Is there a way to build a wiki from within Node without writing the tiddlers to files?
For now, I create several intermediate formats, and it’s easy enough to write these to disk.
I found it frustrating that a JSON file containing an array of JSON-formatted tiddlers doesn’t seem to work with the --load
command. That format works fine for dragging onto an empty wiki. But I don’t want any manual intervention here. I would like this to all run from a Node script, perhaps eventually on a CI/CD server.
I did find a work-around to that. Just wrap those tiddlers like this
<script class="tiddlywiki-tiddler-store" type="application/json">
[ ... tiddlers here ... ]
</script>
and put them in an .html
file. Then I can call something like this1:
const $tw = require('../node_modules/tiddlywiki/boot/boot.js').TiddlyWiki();
// ...
$tw.boot.argv = [
wikiFolder,
`--init`, `server`,
`--load`, tiddlerFile,
`--render`, '$:/plugins/tiddlywiki/tiddlyweb/save/offline', wikiFile, 'text/plain'
]
// ...
$tw.boot.boot()
But that `load` call takes forever! I didn't time it, but I just ran it and it must have taken at least 40 minutes, perhaps as much as an hour. The `render` isn't quick, but I'm pretty sure it's under five minutes, which I can live with for such large wikis.
Another work-around occurs to me: I can manually write all these tiddlers to this temporary tiddlers
folder. I’m sure I can write 32K small files in a small handful of minutes. I will probably try that next.
But I would much, much rather not use the filesystem for this at all. I have these tiddlers as objects in memory. Is there a straightforward way to use them?
1 That leads to another question: I feel as though I’m digging too far into the internals with this method of setting argv
and calling $tw.boot.boot()
. Even requiring TW through node_modules/.../boot.js
seems wrong-headed, even if it works. Is there a more ergonomic technique for calling TW tools from a Node app? (This is less critical to me, as my current technique works. But it feels far too hacky.)