Update tiddlers of single html using external program

I plan to modify the tiddlers of single html file using external program (e.g. R).

My current workflow is to

  • generate tiddlers from R and save as json file
  • drag and drop json file into single html file

I would like to directly inject/modify tiddlers in the single html file.

After looking at the html codes, all tiddlers are stored as json objects under

<script class="tiddlywiki-tiddler-store" type="application/json">
</script>

So my question is whether it is safe to directly modify json objects in the html codes. Are there other ways to modify the single html file?

1 Like

Some different approaches include

  • a package of tiddlers in one wiki which you can see in an iframe, you can drag from the iframed wiki to the current one to install
  • My recently mentioned use of bookmarklets.

The issue about “injecting” is you can do it by editing the html file, perhaps even easier now the tiddlers are stored in JSON, however if someone has the wiki open they may not see the file update and save back over it without keeping the injected tiddlers.

  • One approach I considered was use autosave on the wiki, then once saved start a timer eg 30seconds. Once the 30seconds has passed make the wiki read only so to use it you must reload from disk, and thus catch the tiddlers injected by another process. Or some version there of.
  • Another may be only inject tiddlers at midnight, and save and lock the wiki from saving at midnight, forcing a reload before use.

There are a subset of cases where just loading the “scheduled for injection tiddlers” at open of the wiki for interactive use is feasible, like you are importing content over time and no one else needs to see the “scheduled for injection tiddlers” until the owner opens it interactivly and imports them.

  • This method would benefit from code that detects and input JSON exists and imports its tiddler.
  • This allows the owner to curate injected tiddlers, but is otherwise automated.

It would be great if we could get a way to message a running wiki to tell it what to do if someone is currently using it interactively. Eg Save a logout, or load tiddlers etc…

1 Like

Post script

  • Consider having a published wiki which is only ever updated programmatically, through injection and perhaps a seperate wiki, from which you generate content that updates the published wiki via injection. Then you are never at risk of overwriting injected content.
  • All you want is the visitors to the published site to reload occasionally eg daily/hourly etc… and this can be automated.
1 Like

I don’t worry too much about overwriting by opening TW.

My scenario is to only use my own computer by myself. I would like to inject new results into my summary TW after data analysis in R.

Then I personally would get my analyses to store the updates somewhere, open my wiki and import. Using KISS principal. Make it easier with some of my above ideas but don’t bother injecting, just import.

1 Like

Here is a trick. Output your file to a JSON.

In your wiki use [[download changes|file:///I:/TW5%20Intranet/!Working/check-stamp-field.json]] in a tiddler, now when you open a wiki this tiddler opens and do a r-click save as on the above link and save it in a scratch folder, a temporary folder you regularly delete the content of.

  • Now in chrome the filename is listed at the bottom of the browser, drag and drop it on your wiki, to get the content.
  • In fire fox its the same but you open the download menu and drag it from there.
1 Like

The documentation here might help to learn about that approach: https://tiddlywiki.com/dev/#Data-Storage

@simonw has some python code which inserts tiddlers from a sqlite database into a single-file html instance of TW.

2 Likes

Why the need to inject? Is this a situation where we don’t have access to Node?

If I were to think about including generated data inside my TiddlyWiki I would approach it from a programming perspective. In fact I did just that in my Personal Blog site.

In that example I wanted to embed diagrams into my blog posts. To accomplish this I used a compiler called PlantUML. I used a Makefile that understood how to build any diagrams/*.uml file into an SVG in my tiddlers/generated/ folder along with a *.meta file to add a title and type field for the resulting tiddler.

Then when I ran Make it would build any out-of-date diagrams to the generated folder and then the TiddlyWiki build system would compile a single HTML output which I could copy to any medium I wished.

If you want to directly modify the TiddlyWiki html file, the recommended approach is to add an extra script tag at the beginning of the file, though this cannot overwrite existing tiddlers. See the section called “Multiple store areas and precedence” at the very end of this tiddler: https://tiddlywiki.com/dev/#Data%20Storage%20in%20Single%20File%20TiddlyWiki

The other approach to consider is to use node.js to load the extra tiddlers into the single file wiki and save it again. You would need to use the tiddlywiki on node.js commands load, import and render:

https://tiddlywiki.com/#Commands

1 Like

Thanks @saqimtiaz for your suggestions. PS: I have implemented to use node.js to modify tiddlers.

1 Like