From 627c3e20ccee09f2920df5f3c6a8c385617dc6eb Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Tue, 23 Jan 2024 16:53:12 +0000 Subject: [PATCH] Add docs bags --- .../multiwikiserver/modules/init.js | 7 +++++++ .../modules/sql-tiddler-database.js | 13 +++++++++++++ .../modules/sql-tiddler-store.js | 19 +++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/plugins/tiddlywiki/multiwikiserver/modules/init.js b/plugins/tiddlywiki/multiwikiserver/modules/init.js index 75a520a3c..edf5af985 100644 --- a/plugins/tiddlywiki/multiwikiserver/modules/init.js +++ b/plugins/tiddlywiki/multiwikiserver/modules/init.js @@ -41,6 +41,13 @@ exports.startup = function() { $tw.sqlTiddlerStore = new SqlTiddlerStore({ databasePath: databasePath }); + // Create docs bag and recipe + $tw.sqlTiddlerStore.createBag("docs"); + $tw.sqlTiddlerStore.createRecipe("docs",["docs"],"TiddlyWiki Documentation from https://tiddlywiki.com/"); + $tw.sqlTiddlerStore.saveTiddlersFromPath(path.resolve($tw.boot.corePath,$tw.config.editionsPath,"tw5.com/tiddlers"),"docs"); + $tw.sqlTiddlerStore.createBag("dev-docs"); + $tw.sqlTiddlerStore.createRecipe("dev-docs",["dev-docs"],"TiddlyWiki Developer Documentation from https://tiddlywiki.com/dev/"); + $tw.sqlTiddlerStore.saveTiddlersFromPath(path.resolve($tw.boot.corePath,$tw.config.editionsPath,"dev/tiddlers"),"dev-docs"); // Create bags and recipes $tw.sqlTiddlerStore.createBag("bag-alpha"); $tw.sqlTiddlerStore.createBag("bag-beta"); diff --git a/plugins/tiddlywiki/multiwikiserver/modules/sql-tiddler-database.js b/plugins/tiddlywiki/multiwikiserver/modules/sql-tiddler-database.js index c6dca3aac..520effda1 100644 --- a/plugins/tiddlywiki/multiwikiserver/modules/sql-tiddler-database.js +++ b/plugins/tiddlywiki/multiwikiserver/modules/sql-tiddler-database.js @@ -395,6 +395,19 @@ SqlTiddlerDatabase.prototype.getRecipeTiddlers = function(recipename) { return rows; }; +SqlTiddlerDatabase.prototype.deleteAllTiddlersInBag = function(bagname) { + this.runStatement(` + DELETE FROM tiddlers + WHERE bag_id IN ( + SELECT bag_id + FROM bags + WHERE bag_name = $bag_name + ) + `,{ + bag_name: bagname + }); +}; + /* Get the names of the bags in a recipe. Returns an empty array for recipes that do not exist */ diff --git a/plugins/tiddlywiki/multiwikiserver/modules/sql-tiddler-store.js b/plugins/tiddlywiki/multiwikiserver/modules/sql-tiddler-store.js index f24eb5cea..62a1aafe4 100644 --- a/plugins/tiddlywiki/multiwikiserver/modules/sql-tiddler-store.js +++ b/plugins/tiddlywiki/multiwikiserver/modules/sql-tiddler-store.js @@ -89,6 +89,21 @@ SqlTiddlerStore.prototype.processOutgoingTiddler = function(tiddlerFields,tiddle } }; + +SqlTiddlerStore.prototype.saveTiddlersFromPath = function(tiddler_files_path,bag_name) { + // Clear out the bag + this.deleteAllTiddlersInBag(bag_name); + // Get the tiddlers + var path = require("path"); + var tiddlersFromPath = $tw.loadTiddlersFromPath(path.resolve($tw.boot.corePath,$tw.config.editionsPath,tiddler_files_path)); + // Save the tiddlers + for(const tiddlersFromFile of tiddlersFromPath) { + for(const tiddler of tiddlersFromFile.tiddlers) { + this.saveBagTiddler(tiddler,bag_name); + } + } +}; + SqlTiddlerStore.prototype.logTables = function() { this.sqlTiddlerDatabase.logTables(); }; @@ -190,6 +205,10 @@ SqlTiddlerStore.prototype.getRecipeTiddlers = function(recipename) { return this.sqlTiddlerDatabase.getRecipeTiddlers(recipename); }; +SqlTiddlerStore.prototype.deleteAllTiddlersInBag = function(bagname) { + return this.sqlTiddlerDatabase.deleteAllTiddlersInBag(bagname); +}; + /* Get the names of the bags in a recipe. Returns an empty array for recipes that do not exist */