Method to load batch of images/files and externalize in nodejs server

72 views
Skip to first unread message

Donald Coates

unread,
Mar 9, 2020, 4:01:44 AM3/9/20
to tiddl...@googlegroups.com
Please disregard this and look at the next post.  I am keeping this here as a reference to my own dingdongness

Use: take a directory of images/files and load them into wiki then move them to external folder served by webserver (ie nginx) and (optional) move 'placeholder' files (meta files) to subdirectory.

Method: create subdirectory called loadfiles (doesn't matter) in tiddlers directory. create tiddlywiki.files in loadfiles directory with following:

{
   
"directories": [

       
{
           
"path": "./",
           
"filesRegExp": "^.*\\.(jpg|png|jpeg)$",
           
"isTiddlerFile": false,
           
"fields": {
               
"title": {"source": "filename"},
               
"type": "image/jpeg"
       
}
   
]
}



place all your image files in this directory.

start your wiki if it's not already running. create a tiddler titled set-image-ph-to-yes with the text yes and (optional) create/modify $:/config/FileSystemPaths with text [is[image]addprefix[placehold/images/]] (as per customize file name).

now make a script loadfiles.sh and run:

#!/bin/bash
node
/path/to/tiddlywiki.js \
     
/path/to/wiki \
     
--output /path/to/where/nginx/serves/images/ \                                                            
     
--save [!image-ph[yes]is[image]] \
     
--setfield [!image-ph[yes]is[image]] _canonical_uri $:/core/templates/canonical-uri-external-image text/plain \            
     
--setfield [!image-ph[yes]is[image]] text "" text/plain \
     
--setfield [!image-ph[yes]is[image]] image-ph set-image-ph-to-yes text/plain \

Result: Images/files in loadfiles directory are in the directory nginx serves from and placeholder/reference files (jpg and meta) are in placeholder/images subdirectory of tiddler directory with field image-ph set to yes. This is important so that these reference files do not overwrite the actual image files when you run this next time. Verify everything worked and delete files - except the tiddlywiki.files! - in the loadfiles directory.

NOTE: the files won't show up in your wiki until you restart and tiddlywiki loads the meta files but nginx will be able to serve them right away.  If you use 'savetiddlers' instead of 'save' you have to use the 'noclean' option.

EDIT:  make sure that the path in $:/core/templates/canonical-uri-external-image points to the address in your site's nginx configuration file.

Donald Coates

unread,
Mar 9, 2020, 10:13:46 AM3/9/20
to tiddl...@googlegroups.com
good goddess my ability to overcomplicate is as frightening as it is ridiculous.

The way to do this is to just put all the images in the directory that nginx will be pointing to, lets say images.  Then create a directory in the tiddler directory called loadfiles and put the following tiddlywiki.files in it:

{
   
"directories": [

       
{
           
"path": "../../path/to/nginx/dir/relative/to/this/file",

           
"filesRegExp": "^.*\\.(jpg|png|jpeg)$",
           
"isTiddlerFile": false,
           
"fields": {
               
"title": {"source": "filename"},

               
"type": "image/jpeg",
               "_canonical_uri": {"source": "filename", "prefix": "images/"}
             }
        }
   
]
}

When you start/restart the wiki it will build a reference to this directory and point the browser to it with the canonical uri.  No need for all those extra steps.

Mohammad

unread,
Mar 9, 2020, 10:37:54 AM3/9/20
to TiddlyWiki
Donald,
 There is a little bracket unbalance!

Donald Coates

unread,
Mar 9, 2020, 11:13:42 AM3/9/20
to TiddlyWiki
Thank you!
Reply all
Reply to author
Forward
0 new messages