Create a WikiFolder Under Node.js from a Single TiddlyWiki File

Here is a PowerShell Script to be run from Shell and create a WikiFolder form any TiddlyWiki single html file (like mynotes.html). It uses File System Path configuration as explained in https://tiddlywiki.com/#Customising%20Tiddler%20File%20Naming to create nice folder structure.

File name: singlefilewiki_to_wikifolder.ps1
File content:

param (
    [string]$ExistingWikiPath = "G:\TW\000. Notes\dailynotes.html"
)

$date = Get-Date -Format "yyyy-MM-dd"
$baseFolderName = "daylinotes-wiki-$date"
$folderName = $baseFolderName
$counter = 1

while (Test-Path -Path $folderName) {
    $folderName = "$baseFolderName-$counter"
    $counter++
}

New-Item -ItemType Directory -Path $folderName

Set-Location -Path $folderName
tiddlywiki . --init server

New-Item -ItemType Directory -Path "tiddlers"

$fileContent = @'
title: $:/config/FileSystemPaths

[is[system]!has[draft.of]removeprefix[$:/]addprefix[system/]]
[is[draft]search-replace:g:regexp[/|\\],[_]addprefix[drafts/]]
[tag[task]addprefix[mytasks/]]
[!tag[externalnote]addprefix[wiki/]]
'@

Set-Content -Path "tiddlers/file-system-path.tid" -Value $fileContent

tiddlywiki . --load $ExistingWikiPath

tiddlywiki . --listen port=8080

How it works:

  • It accepts the single file wiki full name (including path, if file is on other drive/foler)
  • it creates a wiki folder like daylinotes-wiki-$date, change as you like
  • if folder existed it adds a number (serial) to the of folder name
  • it creates a config tiddler to set the paths for system/draft/wiki tiddlers (change as you like)
  • it saves the tiddlers from single file TiddlyWiki into wiki folder
  • it then starts the TiddlyWiki at the port=8080 (change as you like)

Remarks

  • I used default value for single file TiddlyWiki ([string]$ExistingWikiPath = "G:\TW\000. Notes\dailynotes.html") change as you like. This will used by default
  • You can call it like .\yourscript.ps1 -ExistingWikiPath "\path\to\ExistingWiki.html"

Requirements

  • Installed Node.js
  • Installed TiddlyWiki on Node.js
  • Windows 10 or above (if you have other OS, you need to have PowerShell installed)

Acknowledgement

3 Likes

The FileSystemPaths here is the key point. But FileSystemPaths in TW is very difficult to use, use addprefix to write down a path is not very clear. It even ask people to write regex, which is even harder to debug.

Hope MWS can fix this by using bags @jeremyruston

Has anyone done this in an automated way to interact with Quine?

I want to store my wiki as files in git (currently I use a big HTML file) for better version control, but edit with Quine on iOS. It’d be nice to have “the best of both worlds” and back the data with git, but use single-file where it makes sense.