Private and public tiddlers in single-file wiki with tw-receiver

133 views
Skip to first unread message

Anjar

unread,
Nov 20, 2020, 8:59:08 AM11/20/20
to TiddlyWiki
Hi all, 

I know there has been some discussions on how to manage to have both public and private tiddlers, so here is my take on the problem:

If we use tw-receiver as the saving mechanism, we can post-process the html file after saving with PHP. The most brutal form would be to simply add

// make a public version
      $doc = new DOMDocument();
      $doc->loadHTML(file_get_contents($destinationfile));    
      $selector = new DOMXPath($doc);
      
      // search for private tiddlers
      $result = $selector->query('//div[contains(@tags, "Private")]');
      
      // loop through all private tiddlers
      $titletext = array();
      foreach($result as $item) {
          $titletext[] = $item->getAttribute("title"); //save the title for later
          $item->parentNode->removeChild($item); // remove the tiddler
      }
      $str_doc = $doc->saveHTML(); // convert to string
      $str_doc = str_replace($titletext, '%%%', $str_doc); // remove all mentions of the private tiddler
      $doc->loadHTML($str_doc); //convert back
      $doc->saveHTMLFile("./public.html"); // save public version

to tw-receiver-server.php (see https://github.com/andjar/tw-receiver). This would create a third output file called public.html and remove all the tiddlers tagged with Private and also replace all mentions of it with %%% (tags, text, links, field etc.). I will try to refine it so that a private tiddler called "link" would not mess up all the html link attributes and so on. Maybe it would be enough to replace in-text links only (and the occurence in the tiddler list in the beginning of the html)?

So one can have an admin wiki protected by basic http auth with drafts and so on, and each time one saves, the public version is updated as well. Then it may be useful to have the tw-receiver password hard coded so that one authentication is enough

Best,
Anders

Donald Coates

unread,
Nov 21, 2020, 11:51:35 PM11/21/20
to TiddlyWiki
I absolutely love tw-receiver it is so incredibly useful.  This looks really interesting I will definitely give it a try.  There are so many php enabled hosts out there I hope folks will look further into this method of hosting and saving as they look for alternatives to tiddlyspot.

TW Tones

unread,
Nov 23, 2020, 1:06:00 AM11/23/20
to TiddlyWiki
Anders, 
I am interested in the idea you suggest and have explored this space before.

Some quick notes;
  • You can use the separate local storage plugin to do the reverse, keep the public on disk and the private in memory
    • Providing a way to export/save the local storage.
  • You can separately encrypt tiddlers.
  • A solution could be built on top of multiple wikis with a variation in permissions for functional reasons and name based files.
  • HTML can be published in tiddlywiki but operate on a PHP host, ie has other file dependencies like javascript and PHP.

Tones

Anjar

unread,
Nov 24, 2020, 5:06:00 PM11/24/20
to TiddlyWiki
Thank you for sharing your thoughts! Including php in the tiddlywiki itself was an intriguing idea

Another idea that comes to mind is to detect if the tiddlywiki has been changed since you opened it and merge the to files instead of overwriting. I guess it should be trivial to make the tw-receiver script compare the versions and make new tiddlers with a specific tag where there is conflic, and then we can use a plugin in the wiki to compare the conflicts when they exist

Anders
Reply all
Reply to author
Forward
0 new messages