From 23fec9e390115c2985e59d2ec1bf6d3cbf5e9a88 Mon Sep 17 00:00:00 2001 From: cdruan <80615570+cdruan@users.noreply.github.com> Date: Tue, 6 Jul 2021 07:02:21 -0700 Subject: [PATCH] Fix faulty external-js single-file wiki (#5570) * Fix problems with building single-file wiki using external-js template * core/templates/external-js/tiddlywiki5-external-js.html.tid, core/templates/external-js/save-all-external-js.tid, core/templates/external-js/save-offline-external-js.tid core/templates/external-js/load-external-js.tid: Fix #5343. Exclude client-server plugins in tiddler imports and to specify a working URL for loading tiddlywiki5.js from local disk. Mirror save/all and save/offline templates in the regular server edition. Fix #4717 (tiddlywiki5-external-js.html.tid) * core/modules/saver-handler.js: Need the change to make single file autosave work with the external-js template. * editions/server-external-js/tiddlywiki.info: Provide external-js related build targets. * core/language/en-GB/Snippets/ExtJSReadme.tid: Temporary doc to supplement TW5.com's external-js section. Demonstrate that upgrade could be done on single-file wikis with an externalized TW core. * core/language/en-GB/Snippets/GetTiddlyWikiJS.tid: Documentation. Meant to be included in every wiki and to help end users acquire tiddlywiki5.js. * Pre-configure save-wiki template for end-users * Remove the newline character at the end of the file. * Trim "template" value in saveWiki() * Safeguard the code from extraneous whitespaces in transcluded result. * Rename and add versioning to downloaded tiddlywiki core JS * Rename "tiddlywiki5.js" to "twcore-VERSION.js" * Preload $:/config/SaveWikiButton/Template tiddler with the required external-js template value. * Update external-js user documentation * Add "download tiddlywiki core JS" menu item to the "cloud" button. * Update build's target defintions associated with external-js template. * Move the user doc to the tw5.com edition. * Coding style update * Undo template name changes * Correct text & fill colors on some disabled buttons * Add new "export tiddlywiki core" button under page control tools This new button can export tiddlywiki's core JS from user's wiki as long as the wiki is served with the regular "root" template. The button will be ineffective, thus disabled, if the core has already been externalized by the "external-js" template. With this button, a full standalone html wiki can obtain the matching core JS without TiddlyWiki on node.js. Once this is done, the html wiki can be converted to using the "external-js" template. * Alternate version of "save tiddlywiki core for offline use" This version will fire up a "Save File" dialogue box when clicked, instead of directing the user to a helper doc for further instruction. It achieves this by using the "download" attribute of the html tag. It works on most modern desktop browsers, but older browsers (e.g. IE) may display the file instead. * Adjust font-weight to match other menu items * Merge two user documentations into one * Add user-browser-cache=yes to --listen command * Update "export tiddlywiki core" button hint * Simpler implementation for switching btw online/offline core URL Shave off one template by using filtered transclusion to control online/offline core URL. * Update user doc Update the user doc to clarify that build index step is not needed to initialize a new wiki. * Rename twcore to tiddlywikicore * Reformat the user doc * Rework export-tiddlywikicore button Popup an error message instead of disabling the button when export core cannot be performed. * Revert "Correct text & fill colors on some disabled buttons" This reverts commit e7dbb7e712e5cd23e57ec068b9fe9ed3bbaf4617. --- core/language/en-GB/Buttons.multids | 2 + core/modules/saver-handler.js | 3 +- .../external-js/save-all-external-js.tid | 1 + .../external-js/save-offline-external-js.tid | 8 ++ .../external-js/tiddlywiki.js.tiddlers.tid | 4 + .../tiddlywiki5-external-js.html.tid | 5 +- .../ui/PageControls/export-tiddlywikicore.tid | 25 +++++ core/wiki/config/PageControlButtons.multids | 1 + core/wiki/tags/PageControls.tid | 2 +- editions/server-external-js/tiddlywiki.info | 11 ++- ...Using the external JavaScript template.tid | 96 ++++++++++++++++--- editions/tw5.com/tiddlywiki.info | 4 +- ...syncer-actions-download-tiddlywikicore.tid | 7 ++ .../tiddlyweb/tags-syncerdropdown.tid | 2 +- 14 files changed, 148 insertions(+), 23 deletions(-) create mode 100644 core/templates/external-js/save-offline-external-js.tid create mode 100644 core/ui/PageControls/export-tiddlywikicore.tid create mode 100644 plugins/tiddlywiki/tiddlyweb/syncer-actions-download-tiddlywikicore.tid diff --git a/core/language/en-GB/Buttons.multids b/core/language/en-GB/Buttons.multids index 83598f410..e1b2b1372 100644 --- a/core/language/en-GB/Buttons.multids +++ b/core/language/en-GB/Buttons.multids @@ -32,6 +32,8 @@ ExportTiddler/Caption: export tiddler ExportTiddler/Hint: Export tiddler ExportTiddlers/Caption: export tiddlers ExportTiddlers/Hint: Export tiddlers +ExportTiddlyWikiCore/Caption: export TiddlyWiki core +ExportTiddlyWikiCore/Hint: Export the ~TiddlyWiki core code for running with external ~JavaScript SidebarSearch/Hint: Select the sidebar search field Fold/Caption: fold tiddler Fold/Hint: Fold the body of this tiddler diff --git a/core/modules/saver-handler.js b/core/modules/saver-handler.js index e2ac21361..119c3e67a 100644 --- a/core/modules/saver-handler.js +++ b/core/modules/saver-handler.js @@ -157,7 +157,8 @@ SaverHandler.prototype.saveWiki = function(options) { return false; } var variables = options.variables || {}, - template = options.template || "$:/core/save/all", + template = (options.template || + this.wiki.getTiddlerText("$:/config/SaveWikiButton/Template","$:/core/save/all")).trim(), downloadType = options.downloadType || "text/plain", text = this.wiki.renderTiddler(downloadType,template,options), callback = function(err) { diff --git a/core/templates/external-js/save-all-external-js.tid b/core/templates/external-js/save-all-external-js.tid index 51f6d6508..a41cc0682 100644 --- a/core/templates/external-js/save-all-external-js.tid +++ b/core/templates/external-js/save-all-external-js.tid @@ -4,4 +4,5 @@ title: $:/core/save/all-external-js \define saveTiddlerFilter() [is[tiddler]] -[prefix[$:/state/popup/]] -[prefix[$:/temp/]] -[prefix[$:/HistoryList]] -[status[pending]plugin-type[import]] -[[$:/core]] -[[$:/boot/boot.css]] -[type[application/javascript]library[yes]] -[[$:/boot/boot.js]] -[[$:/boot/bootprefix.js]] +[sort[title]] $(publishFilter)$ \end +\define coreURL() %24%3A%2Fcore%2Ftemplates%2Ftiddlywiki5.js {{$:/core/templates/tiddlywiki5-external-js.html}} diff --git a/core/templates/external-js/save-offline-external-js.tid b/core/templates/external-js/save-offline-external-js.tid new file mode 100644 index 000000000..7175f7eea --- /dev/null +++ b/core/templates/external-js/save-offline-external-js.tid @@ -0,0 +1,8 @@ +title: $:/core/save/offline-external-js + +\import [[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]] +\define saveTiddlerFilter() +[is[tiddler]] -[prefix[$:/state/popup/]] -[prefix[$:/temp/]] -[prefix[$:/HistoryList]] -[status[pending]plugin-type[import]] -[[$:/core]] -[[$:/plugins/tiddlywiki/filesystem]] -[[$:/plugins/tiddlywiki/tiddlyweb]] -[[$:/boot/boot.css]] -[type[application/javascript]library[yes]] -[[$:/boot/boot.js]] -[[$:/boot/bootprefix.js]] +[sort[title]] $(publishFilter)$ +\end +\define coreURL() tiddlywikicore-$(version)$.js +{{$:/core/templates/tiddlywiki5-external-js.html}} diff --git a/core/templates/external-js/tiddlywiki.js.tiddlers.tid b/core/templates/external-js/tiddlywiki.js.tiddlers.tid index 322e7ae5e..3b5d1bfe6 100644 --- a/core/templates/external-js/tiddlywiki.js.tiddlers.tid +++ b/core/templates/external-js/tiddlywiki.js.tiddlers.tid @@ -2,4 +2,8 @@ title: $:/core/templates/tiddlywiki5.js/tiddlers ` $tw.preloadTiddlerArray(`<$text text=<>/>`); +$tw.preloadTiddlerArray([{ + title: "$:/config/SaveWikiButton/Template", + text: "$:/core/save/offline-external-js" +}]); ` diff --git a/core/templates/external-js/tiddlywiki5-external-js.html.tid b/core/templates/external-js/tiddlywiki5-external-js.html.tid index 31e583c6c..6a5c4c1bb 100644 --- a/core/templates/external-js/tiddlywiki5-external-js.html.tid +++ b/core/templates/external-js/tiddlywiki5-external-js.html.tid @@ -2,7 +2,7 @@ title: $:/core/templates/tiddlywiki5-external-js.html \rules only filteredtranscludeinline transcludeinline -{{$:/core/templates/MOTW.html}} +{{$:/core/templates/MOTW.html}} @@ -43,5 +43,6 @@ title: $:/core/templates/tiddlywiki5-external-js.html {{{ [all[shadows+tiddlers]tag[$:/tags/RawMarkupWikified/BottomBody]] ||$:/core/templates/raw-static-tiddler}}} - + + diff --git a/core/ui/PageControls/export-tiddlywikicore.tid b/core/ui/PageControls/export-tiddlywikicore.tid new file mode 100644 index 000000000..77436dc9e --- /dev/null +++ b/core/ui/PageControls/export-tiddlywikicore.tid @@ -0,0 +1,25 @@ +title: $:/core/ui/Buttons/export-tiddlywikicore +tags: $:/tags/PageControls +caption: {{$:/core/images/star-filled}} {{$:/language/Buttons/ExportTiddlyWikiCore/Caption}} +description: {{$:/language/Buttons/ExportTiddlyWikiCore/Hint}} + +\whitespace trim +\define jsFileName() tiddlywikicore-$(version)$.js +\define noExportMsg() +It appears that you have a wiki with an external ~TiddlyWiki core. The export action cannot be performed. +

You will need to view the page source in your browser. Then go to the very bottom the the source, find the last `