1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-08-08 23:03:50 +00:00

Initial Commit

This commit is contained in:
Jeremy Ruston 2025-02-16 18:20:00 +00:00
parent c84de85ed2
commit 778e544f1c
8 changed files with 94 additions and 42 deletions

View File

@ -1163,7 +1163,7 @@ $tw.Wiki = function(options) {
options = options || {}; options = options || {};
var self = this, var self = this,
tiddlers = Object.create(null), // Hashmap of tiddlers tiddlers = Object.create(null), // Hashmap of tiddlers
tiddlerTitles = null, // Array of tiddler titles tiddlerTitles = null, // Array of tiddler titles, calculated and cached when needed
getTiddlerTitles = function() { getTiddlerTitles = function() {
if(!tiddlerTitles) { if(!tiddlerTitles) {
tiddlerTitles = Object.keys(tiddlers).sort(function(a,b) {return a.localeCompare(b);}); tiddlerTitles = Object.keys(tiddlers).sort(function(a,b) {return a.localeCompare(b);});
@ -1173,7 +1173,7 @@ $tw.Wiki = function(options) {
pluginTiddlers = [], // Array of tiddlers containing registered plugins, ordered by priority pluginTiddlers = [], // Array of tiddlers containing registered plugins, ordered by priority
pluginInfo = Object.create(null), // Hashmap of parsed plugin content pluginInfo = Object.create(null), // Hashmap of parsed plugin content
shadowTiddlers = Object.create(null), // Hashmap by title of {source:, tiddler:} shadowTiddlers = Object.create(null), // Hashmap by title of {source:, tiddler:}
shadowTiddlerTitles = null, shadowTiddlerTitles = null, // Array of tiddler titles, calculated and cached when needed
getShadowTiddlerTitles = function() { getShadowTiddlerTitles = function() {
if(!shadowTiddlerTitles) { if(!shadowTiddlerTitles) {
shadowTiddlerTitles = Object.keys(shadowTiddlers).sort(function(a,b) {return a.localeCompare(b);}); shadowTiddlerTitles = Object.keys(shadowTiddlers).sort(function(a,b) {return a.localeCompare(b);});
@ -1500,7 +1500,7 @@ $tw.Wiki = function(options) {
}); });
} }
}); });
shadowTiddlerTitles = null; shadowTiddlerTitles = null; // Force regeneration of the shadow tiddler titles list
this.clearCache(null); this.clearCache(null);
this.clearGlobalCache(); this.clearGlobalCache();
$tw.utils.each(indexers,function(indexer) { $tw.utils.each(indexers,function(indexer) {
@ -1936,7 +1936,7 @@ $tw.boot.excludeRegExp = /^\.DS_Store$|^.*\.meta$|^\..*\.swp$|^\._.*$|^\.git$|^\
/* /*
Load all the tiddlers recursively from a directory, including honouring `tiddlywiki.files` files for drawing in external files. Returns an array of {filepath:,type:,tiddlers: [{..fields...}],hasMetaFile:}. Note that no file information is returned for externally loaded tiddlers, just the `tiddlers` property. Load all the tiddlers recursively from a directory, including honouring `tiddlywiki.files` files for drawing in external files. Returns an array of {filepath:,type:,tiddlers: [{..fields...}],hasMetaFile:}. Note that no file information is returned for externally loaded tiddlers, just the `tiddlers` property.
*/ */
$tw.loadTiddlersFromPath = function(filepath,excludeRegExp) { $tw.loadTiddlersFromPath = function(filepath,excludeRegExp,excludePluginInfo) {
excludeRegExp = excludeRegExp || $tw.boot.excludeRegExp; excludeRegExp = excludeRegExp || $tw.boot.excludeRegExp;
var tiddlers = []; var tiddlers = [];
if(fs.existsSync(filepath)) { if(fs.existsSync(filepath)) {
@ -1946,11 +1946,16 @@ $tw.loadTiddlersFromPath = function(filepath,excludeRegExp) {
// Look for a tiddlywiki.files file // Look for a tiddlywiki.files file
if(files.indexOf("tiddlywiki.files") !== -1) { if(files.indexOf("tiddlywiki.files") !== -1) {
Array.prototype.push.apply(tiddlers,$tw.loadTiddlersFromSpecification(filepath,excludeRegExp)); Array.prototype.push.apply(tiddlers,$tw.loadTiddlersFromSpecification(filepath,excludeRegExp));
} else if(files.indexOf("plugin.info") !== -1 && !excludePluginInfo) {
var tiddler = $tw.loadPluginFolder(filepath);
if(tiddler) {
tiddlers.push({tiddlers: [tiddler]});
}
} else { } else {
// If not, read all the files in the directory // If not, read all the files in the directory
$tw.utils.each(files,function(file) { $tw.utils.each(files,function(file) {
if(!excludeRegExp.test(file) && file !== "plugin.info") { if(!excludeRegExp.test(file) && file !== "plugin.info") {
tiddlers.push.apply(tiddlers,$tw.loadTiddlersFromPath(filepath + path.sep + file,excludeRegExp)); tiddlers.push.apply(tiddlers,$tw.loadTiddlersFromPath(path.join(filepath,file),excludeRegExp));
} }
}); });
} }
@ -2097,54 +2102,69 @@ Load the tiddlers from a plugin folder, and package them up into a proper JSON p
*/ */
$tw.loadPluginFolder = function(filepath,excludeRegExp) { $tw.loadPluginFolder = function(filepath,excludeRegExp) {
excludeRegExp = excludeRegExp || $tw.boot.excludeRegExp; excludeRegExp = excludeRegExp || $tw.boot.excludeRegExp;
var infoPath = filepath + path.sep + "plugin.info"; function readPluginFields(filepath) {
if(fs.existsSync(filepath) && fs.statSync(filepath).isDirectory()) { if(!(fs.existsSync(filepath) && fs.statSync(filepath).isDirectory())) {
// Read the plugin information
if(!fs.existsSync(infoPath) || !fs.statSync(infoPath).isFile()) {
console.log("Warning: missing plugin.info file in " + filepath);
return null; return null;
} }
var pluginInfo = $tw.utils.parseJSONSafe(fs.readFileSync(infoPath,"utf8"),function() {return null;}); var infoPath = path.join(filepath,"plugin.info");
if(!pluginInfo) { // Read the plugin information file
console.log("warning: invalid JSON in plugin.info file at " + infoPath); if(!fs.existsSync(infoPath) || !fs.statSync(infoPath).isFile()) {
pluginInfo = {}; return null;
} }
// Read the plugin files var pluginFields = $tw.utils.parseJSONSafe(fs.readFileSync(infoPath,"utf8"),{});
var pluginFiles = $tw.loadTiddlersFromPath(filepath,excludeRegExp); if(!(pluginFields.title && pluginFields.name)) {
// Save the plugin tiddlers into the plugin info return null;
pluginInfo.tiddlers = pluginInfo.tiddlers || Object.create(null); }
// Give the plugin the same version number as the core if it doesn't have one
if(!("version" in pluginFields)) {
pluginFields.version = $tw.packageInfo.version;
}
// Use "plugin" as the plugin-type if we don't have one
if(!("plugin-type" in pluginFields)) {
pluginFields["plugin-type"] = "plugin";
}
// Set the dependents and type
pluginFields.dependents = pluginFields.dependents || [];
pluginFields.type = "application/json";
// Deserialise array fields (currently required for the dependents field)
for(var field in pluginFields) {
if($tw.utils.isArray(pluginFields[field])) {
pluginFields[field] = $tw.utils.stringifyList(pluginFields[field]);
}
}
return pluginFields;
}
function readPluginTiddlers(tiddlersPath) {
var pluginFiles = $tw.loadTiddlersFromPath(tiddlersPath,excludeRegExp,true),
pluginTiddlers = {};
// Save the plugin tiddlers into the plugin payload
for(var f=0; f<pluginFiles.length; f++) { for(var f=0; f<pluginFiles.length; f++) {
var tiddlers = pluginFiles[f].tiddlers; var tiddlers = pluginFiles[f].tiddlers;
if(!tiddlers) {
console.log(`Gosh ${JSON.stringify(pluginFiles[f])}`)
}
for(var t=0; t<tiddlers.length; t++) { for(var t=0; t<tiddlers.length; t++) {
var tiddler= tiddlers[t]; var tiddler= tiddlers[t];
if(tiddler.title) { if(tiddler.title) {
pluginInfo.tiddlers[tiddler.title] = tiddler; pluginTiddlers[tiddler.title] = tiddler;
} }
} }
} }
// Give the plugin the same version number as the core if it doesn't have one return pluginTiddlers;
if(!("version" in pluginInfo)) {
pluginInfo.version = $tw.packageInfo.version;
}
// Use "plugin" as the plugin-type if we don't have one
if(!("plugin-type" in pluginInfo)) {
pluginInfo["plugin-type"] = "plugin";
}
pluginInfo.dependents = pluginInfo.dependents || [];
pluginInfo.type = "application/json";
// Set plugin text
pluginInfo.text = JSON.stringify({tiddlers: pluginInfo.tiddlers});
delete pluginInfo.tiddlers;
// Deserialise array fields (currently required for the dependents field)
for(var field in pluginInfo) {
if($tw.utils.isArray(pluginInfo[field])) {
pluginInfo[field] = $tw.utils.stringifyList(pluginInfo[field]);
}
}
return pluginInfo;
} else {
return null;
} }
// Get the primary plugin fields
var pluginFields = readPluginFields(filepath);
if(!pluginFields) {
console.log("Warning: missing or invalid plugin.info file in " + filepath);
return null;
}
// The payload to be stored in the plugin text field in JSON
var pluginPayload = {tiddlers: {}};
// Get the constituent tiddlers of the plugin
pluginPayload.tiddlers = readPluginTiddlers(filepath);
// Set plugin text
pluginFields.text = JSON.stringify(pluginPayload);
return pluginFields;
}; };
/* /*

View File

@ -7,7 +7,8 @@
"tiddlywiki/menubar", "tiddlywiki/menubar",
"tiddlywiki/confetti", "tiddlywiki/confetti",
"tiddlywiki/dynannotate", "tiddlywiki/dynannotate",
"tiddlywiki/tour" "tiddlywiki/tour",
"tiddlywiki/intrinsic-subplugin-tests"
], ],
"themes": [ "themes": [
"tiddlywiki/vanilla", "tiddlywiki/vanilla",

View File

@ -0,0 +1,7 @@
{
"title": "$:/plugins/tiddlywiki/intrinsic-subplugin-tests",
"name": "intrinsic-subplugin-tests",
"description": "Intrinsic subplugin tests",
"list": "readme",
"stability": "STABILITY_1_EXPERIMENTAL"
}

View File

@ -0,0 +1,4 @@
title: $:/plugins/tiddlywiki/intrinsic-subplugin-tests/readme
Readme from $:/plugins/tiddlywiki/intrinsic-subplugin-tests

View File

@ -0,0 +1,7 @@
{
"title": "$:/plugins/tiddlywiki/test-subplugin",
"name": "test-subplugin",
"description": "Test subplugin",
"list": "readme",
"stability": "STABILITY_1_EXPERIMENTAL"
}

View File

@ -0,0 +1,3 @@
title: $:/plugins/tiddlywiki/test-subplugin/readme
Readme from $:/plugins/tiddlywiki/test-subplugin

View File

@ -0,0 +1,7 @@
{
"title": "$:/plugins/tiddlywiki/test-subsubplugin",
"name": "test-subsubplugin",
"description": "Test subsubplugin",
"list": "readme readme2",
"stability": "STABILITY_1_EXPERIMENTAL"
}

View File

@ -0,0 +1,3 @@
title: $:/plugins/tiddlywiki/test-subsubplugin/readme
Readme from $:/plugins/tiddlywiki/test-subsubplugin