From c1a1e272cc9b823f97f8f1bde6a24dfa5fe973e8 Mon Sep 17 00:00:00 2001 From: jed Date: Mon, 14 Dec 2020 00:24:23 +0100 Subject: [PATCH] Add a hook to allow modifying the the behaviour creating tiddler paths (#5267) * Add a hook to allow modifying the the behaviour creating tiddler paths This is needed for Bob to use the core to generate tiddler fileInfo I don't know if this is the best way to make the hook, but it works for what I need * update th-make-tiddler-path arguments the value is the current path, the parameter passed in is the original unmodified path so it is available to subsequent hooks --- core/modules/utils/filesystem.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/modules/utils/filesystem.js b/core/modules/utils/filesystem.js index eb1050f90..e616f9f70 100644 --- a/core/modules/utils/filesystem.js +++ b/core/modules/utils/filesystem.js @@ -382,11 +382,13 @@ exports.generateTiddlerFilepath = function(title,options) { count++; } while(fs.existsSync(fullPath)); //If the path does not start with the wikiPath directory or the wikiTiddlersPath directory, or if the last write failed - var encode = !(fullPath.indexOf(path.resolve($tw.boot.wikiPath)) == 0 || fullPath.indexOf($tw.boot.wikiTiddlersPath) == 0) || ((options.fileInfo || {writeError: false}).writeError == true); + var newPath = fullPath; + var encode = !(fullPath.indexOf($tw.boot.wikiPath) == 0 || fullPath.indexOf($tw.boot.wikiTiddlersPath) == 0) || ((options.fileInfo || {writeError: false}).writeError == true); if(encode){ //encodeURIComponent() and then resolve to tiddler directory - fullPath = path.resolve(directory, encodeURIComponent(fullPath)); + newPath = path.resolve(directory, encodeURIComponent(fullPath)); } + fullPath = $tw.hooks.invokeHook("th-make-tiddler-path", newPath, fullPath); // Return the full path to the file return fullPath; };