1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-24 17:10:29 +00:00

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
This commit is contained in:
James Welford Anderson 2015-02-21 06:45:40 +09:00
parent 3df341621d
commit ee6b6a0f0c
3 changed files with 9 additions and 2 deletions

View File

@ -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;
};

View File

@ -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)) {

View File

@ -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'/></$transclude>"