How to create a "save to github" button/trigger a save with a specific saver (single file wiki)?

65 views
Skip to first unread message

Télumire

unread,
Aug 10, 2021, 1:09:58 PM8/10/21
to TiddlyWiki

Hello everyone,

I wish to use tiddlywiki as a semi-private blog using GitHub Pages (with some of its content never going online until it's ready) and thought it would be nice to have a button that allow to choose what saver to use.

For example, when I'm finished working on my article, I would hit the regular save button and the changes would be saved locally. Then, when I'm satisfied, I would click a button to save to GitHub.

The interesting thing is that we can set a filter to exclude some tiddler from the save, so if I want to exclude an unfinished tiddler from the save to GitHub, I would simply tag it with “private” or something before saving the wiki.

The issue is : tiddlywiki does not provide a mean to specify which saver to use when triggering a save.

I found a workaround : I use a button which first fill in the GitHub credential, increasing the priority of the GitHub saver, trigger the filtered save, then remove the credential, allowing the next regular save to be done with the local saver.

The issue is that when I save to github this way, it also save locally. So to prevent my private tiddlers from getting overridden by the save, I need to trigger a complete save to finish the process. I think this is very risky because if the browser crash between the github save and the local save, all my private tiddlers will be lost. It would be best if I could save only to github thus never overriding my local wiki. Is that possible ?

I've found this js code by bimlas showing how to select a saver : https://bimlas.gitlab.io/demo/tw5/preferred-saver.html#%24%3A%2Fbimlas%2Fpreferred-saver.js but I don't know how to adapt it to my scenario.

Here's the code that I use for now :

<$button tooltip={{GithubSave/Hint}} aria-label={{GithubSave/Caption}}  class=<<tv-config-toolbar-class>>>
<$action-listops $tiddler="github save button/private/username" $tags="[[private]] [[github save button]]"/>
<$action-listops $tiddler="github save button/private/state" $tags="[[private]] [[github save button]]"/>
<$action-setfield $tiddler="$:/GitHub/Username" text={{github save button/private/username}}/>
<$action-sendmessage $message="tm-save-wiki" $param="$:/core/save/all" publishFilter={{publishFilter}} />
<$action-setfield $tiddler="$:/GitHub/Username" text=""/>
<$action-sendmessage $message="tm-save-wiki" $param="$:/core/save/all"/>

<span class="tc-dirty-indicator">
<$list filter="[<tv-config-toolbar-icons>match[yes]]">
{{$:/core/images/github}}
</$list>
<$list filter="[<tv-config-toolbar-text>match[yes]]">
<span class="tc-btn-text">save to github</span>
</$list>
</span>
</$button>


Live demo :

https://telumire.github.io/TW-tips/#Save%20a%20private%20copy%20to%20github%20(single%20file%20wiki)

You can import it in your wiki by drag & drop "'open all in the current tab" in tiddlywiki. Click once on the button, then fill in the username in the tiddler "github save button/private/username".

Saq Imtiaz

unread,
Aug 10, 2021, 1:46:26 PM8/10/21
to TiddlyWiki
I think bimlas' code has most of what you need and could easily be adapted for your purposes.
You may want to consider speaking with him, see https://groups.google.com/g/tiddlywiki/c/ZU_s6FdUy8Q/m/KeXVnOciBAAJ

Also helpful might be the ability to create a custom save button that does not include the public content. See the following shadow tiddlers:
$:/core/ui/Buttons/save-wiki
$:/config/SaveWikiButton/Template
$:/core/save/all

Télumire

unread,
Aug 10, 2021, 2:00:43 PM8/10/21
to TiddlyWiki
Hi Saq,

The code I shared at the end of my post already use these shadow tiddlers.
Thanks for the google thread, I'll try again and ask him for help if need be.

I just hopped there was a way to do that in wiki text only, since I'm not very good with JavaScript ^^

Saq Imtiaz

unread,
Aug 10, 2021, 2:20:32 PM8/10/21
to TiddlyWiki
Regarding: " It would be best if I could save only to github thus never overriding my local wiki. Is that possible ?"

Have you tried removing the second instance of  $action-sendmessage $message="tm-save-wiki" in your code?

Saq Imtiaz

unread,
Aug 10, 2021, 2:32:33 PM8/10/21
to TiddlyWiki
Ah right, I believe there is a race condition which is leading to the double save. 

Saq Imtiaz

unread,
Aug 10, 2021, 3:31:09 PM8/10/21
to TiddlyWiki
OK I needed to be at a proper keyboard to write this out. Try the following:

\define myactions()
<$action-sendmessage $message="tm-save-wiki" $param="$:/core/save/all" publishFilter={{publishFilter}} />
<$action-setfield $tiddler="$:/GitHub/Username" text=""/>
\end

<$button tooltip={{GithubSave/Hint}} aria-label={{GithubSave/Caption}}  class=<<tv-config-toolbar-class>> actions=<<myactions>>>
<$action-listops $tiddler="github save button/private/username" $tags="[[private]] [[github save button]]"/>
<$action-listops $tiddler="github save button/private/state" $tags="[[private]] [[github save button]]"/>
<$action-setfield $tiddler="$:/GitHub/Username" text={{github save button/private/username}}  />
<span class="tc-dirty-indicator">
<$list filter="[<tv-config-toolbar-icons>match[yes]]">
{{$:/core/images/github}}
</$list>
<$list filter="[<tv-config-toolbar-text>match[yes]]">
<span class="tc-btn-text">save to github</span>
</$list>
</span>
</$button>

Télumire

unread,
Aug 10, 2021, 3:43:17 PM8/10/21
to TiddlyWiki
As I said : the issue is that when I save to github this way, it also save locally. So to prevent my private tiddlers from getting overridden by the save, I need to trigger a complete save to finish the process.

Now that I think about it, it's probably because of the action-setfield widget : it must trigger an automatic save when the tiddler $:/GitHub/Username is edited .. maybe I could prevent this by temporarily setting $:/config/AutoSave to "no" !

Yep, this works ! https://telumire.github.io/test-github-save.html

Télumire

unread,
Aug 10, 2021, 3:50:24 PM8/10/21
to TiddlyWiki
I tried your code but for some reason I get a 404 error, maybe it's because of the order by which tiddlywiki run the macros ?
In any case, it seems like the culprit was indeed the autosave, here's the fix :


<$button tooltip={{GithubSave/Hint}} aria-label={{GithubSave/Caption}}  class=<<tv-config-toolbar-class>>>
<$action-setfield $tiddler="$:/config/AutoSave" text="no"/>


<$action-listops $tiddler="github save button/private/username" $tags="[[private]] [[github save button]]"/>
<$action-listops $tiddler="github save button/private/state" $tags="[[private]] [[github save button]]"/>
<$action-setfield $tiddler="$:/GitHub/Username" text={{github save button/private/username}}/>
<$action-sendmessage $message="tm-save-wiki" $param="$:/core/save/all" publishFilter={{publishFilter}} />
<$action-setfield $tiddler="$:/GitHub/Username" text=""/>
<$action-setfield $tiddler="$:/config/AutoSave" text="yes"/>


<span class="tc-dirty-indicator">
<$list filter="[<tv-config-toolbar-icons>match[yes]]">
{{$:/core/images/github}}
</$list>
<$list filter="[<tv-config-toolbar-text>match[yes]]">
<span class="tc-btn-text">save to github</span>
</$list>
</span>
</$button>

TW Tones

unread,
Aug 10, 2021, 7:01:53 PM8/10/21
to TiddlyWiki
Without digging into the details perhaps the publish process is just generating a single file wiki and publishing that on GitHub, even if you are storing individual tiddlers on git hub.

Otherwise just use the node wiki for your work. In this case the publish is only a matter for a file download button.

Tones
Reply all
Reply to author
Forward
0 new messages