From ee6b6a0f0ccf4b5bad9588ab4ccda0180b5d851f Mon Sep 17 00:00:00 2001 From: James Welford Anderson Date: Sat, 21 Feb 2015 06:45:40 +0900 Subject: [PATCH 1/2] add macros for custom statically exported paths/links/images tv-get-export-path tells render tiddlers where to export files tv-get-export-image-link tells images.js where to look for images tv-get-export-link tells tells link.js where to look for links to other exported tiddlers --- core/modules/commands/rendertiddlers.js | 8 +++++++- core/modules/widgets/image.js | 2 +- core/modules/widgets/link.js | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/core/modules/commands/rendertiddlers.js b/core/modules/commands/rendertiddlers.js index d02d98417..60c5b8702 100644 --- a/core/modules/commands/rendertiddlers.js +++ b/core/modules/commands/rendertiddlers.js @@ -50,7 +50,13 @@ Command.prototype.execute = function() { var container = $tw.fakeDocument.createElement("div"); widgetNode.render(container,null); var text = type === "text/html" ? container.innerHTML : container.textContent; - fs.writeFileSync(path.resolve(pathname,encodeURIComponent(title) + extension),text,"utf8"); + var export_path = null; + if($tw.utils.hop($tw.macros,"tv-get-export-path")) { + export_path = path.resolve(outputPath,$tw.macros["tv-get-export-path"].run.apply(self,[title]) + extension); + } + var final_path = export_path || path.resolve(pathname,encodeURIComponent(title) + extension); + $tw.utils.createFileDirectories(final_path); + fs.writeFileSync(final_path,text,"utf8"); }); return null; }; diff --git a/core/modules/widgets/image.js b/core/modules/widgets/image.js index afa8b447b..50c0703b1 100644 --- a/core/modules/widgets/image.js +++ b/core/modules/widgets/image.js @@ -52,7 +52,7 @@ ImageWidget.prototype.render = function(parent,nextSibling) { tiddler = this.wiki.getTiddler(this.imageSource); if(!tiddler) { // The source isn't the title of a tiddler, so we'll assume it's a URL - src = this.imageSource; + src = this.getVariable("tv-get-export-image-link",{params: [{name: "src",value: this.imageSource}],defaultValue: this.imageSource}); } else { // Check if it is an image tiddler if(this.wiki.isImageTiddler(this.imageSource)) { diff --git a/core/modules/widgets/link.js b/core/modules/widgets/link.js index ff7209ec4..ebb3b413c 100755 --- a/core/modules/widgets/link.js +++ b/core/modules/widgets/link.js @@ -77,6 +77,7 @@ LinkWidget.prototype.renderLink = function(parent,nextSibling) { wikiLinkTemplate = wikiLinkTemplateMacro ? wikiLinkTemplateMacro.trim() : "#$uri_encoded$", wikiLinkText = wikiLinkTemplate.replace("$uri_encoded$",encodeURIComponent(this.to)); wikiLinkText = wikiLinkText.replace("$uri_doubleencoded$",encodeURIComponent(encodeURIComponent(this.to))); + wikiLinkText = this.getVariable("tv-get-export-link",{params: [{name: "to",value: this.to}],defaultValue: wikiLinkText}); domNode.setAttribute("href",wikiLinkText); // Set the tooltip // HACK: Performance issues with re-parsing the tooltip prevent us defaulting the tooltip to "<$transclude field='tooltip'><$transclude field='title'/>" From cf59e7a71b4aadae0b4870ea1b705c8c9f2e1766 Mon Sep 17 00:00:00 2001 From: James Welford Anderson Date: Sat, 21 Feb 2015 06:49:34 +0900 Subject: [PATCH 2/2] re-add outputpath variable --- core/modules/commands/rendertiddlers.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/modules/commands/rendertiddlers.js b/core/modules/commands/rendertiddlers.js index 60c5b8702..782459e44 100644 --- a/core/modules/commands/rendertiddlers.js +++ b/core/modules/commands/rendertiddlers.js @@ -35,7 +35,8 @@ Command.prototype.execute = function() { wiki = this.commander.wiki, filter = this.params[0], template = this.params[1], - pathname = path.resolve(this.commander.outputPath,this.params[2]), + outputPath = this.commander.outputPath, + pathname = path.resolve(outputPath,this.params[2]), type = this.params[3] || "text/html", extension = this.params[4] || ".html", deleteDirectory = (this.params[5] || "") != "noclean",