Continuing the discussion from What is the advantage of Node js. over html file?:
Here’s a summary of several tips and tricks you can use to improve your experience with tiddlywiki on node.js. This post is a wiki, feel free to contribute to it!
1. (windows) Using a .bat file to automate the creation/launch of wikis
@ECHO off
IF NOT "%~1"=="" (
::if using shortcut
set name=%~1
) ELSE (
::ask for the name
set /p name=Name of the wiki:
)
::remove quotations
set name=%name:"=%
ECHO %name% will open shortly..
::search free port
set startPort=80
:SEARCHPORT
netstat -o -n -a | find "LISTENING" | find ":%startPort% " > NUL
IF "%ERRORLEVEL%" equ "0" (
set /a startPort +=1
GOTO :SEARCHPORT
) ELSE (
set freePort=%startPort%
GOTO :FOUNDPORT
)
:FOUNDPORT
::launch tiddlywiki server
CALL tiddlywiki "%name%" --init server
::open the url in the default browser
START http://localhost:%freePort%
::create shortcuts files if missing
IF NOT EXIST "%name%/start.bat" ECHO for %%%%d in ^(^.^) do cd.. ^& start.bat "%%%%~nxd" >"%name%/start.bat"
IF NOT EXIST "%name%/backup.bat" ECHO tiddlywiki --build index >"%name%/backup.bat"
::set title of the wiki if blank
IF NOT EXIST "%name%/tiddlers/$__SiteTitle.tid" (
ECHO {"title":"$:/SiteTitle","text":"%name%"} >"%name%/title.json"
CALL tiddlywiki "%name%" --load "%name%/title.json"
)
::listen to a free port
CALL tiddlywiki "%name%" --listen port=%freePort%
Download : https://github.com/Telumire/StartTWNodeJS/releases/download/v0.0.1/start.bat
To use :
- Download the .bat or create a text file, copy/paste the above code, then save and change the extension to
.bat
. - If node.js is installed, double-clicking that file in a folder will open a command prompt asking for the name of the wiki to be created, then a folder will be created with that name and the wiki will launch in the default internet browser.
- A batch file to start the wiki and another to create a single file backup of the wiki will be created inside the wiki’s folder, for later use.
- You can then create a shortcut of this batch file and place it into “C:\ProgramData\Microsoft\Windows\Start Menu” to be able to pin the shortcut to the start menu, or put it anywhere else you like. It’s also possible to customize the icon of the shortcut, create a keyboard shortcut and schedule your wiki to be opened automatically on startup.
2. (windows) Compress your folder to save space
Thanks to @pmario for this tip !Note : The startup time may be slightly slower with compression enabled
- Left click on the folder, then press alt+enter (or click on the properties button in the Home tab of the file explorer, or use the right-click menu).
- In the properties window, in the General tab, click on the “Advanced…” button and check the “Compress contents to save disk space” option
In a test with 10k tiddlers containing each 2783 characters, the results were as follow :
- Size: 28 964 499 bytes
- Size on disk: 40 964 096 bytes
- Space saved : (40964096 - 28964499)/40964096 ≈ 30%
3. Using a .cmd file to upgrade a single file wiki with node.js
Tip shared by @amreus here : Update a single-file TiddlyWiki from the command line
Batch file code :
copy "%1" "%1"-%RANDOM%
tiddlywiki --load "%1" --output . --render "$:/core/save/all" "%1" "text/plain"
Using the batch file (named twup.cmd
) :
twup mywiki.html
backup your wiki before performing this operation !
EDIT: upgraded the batch file to automate the creation/launch of multiple wikis and set the title of the wiki