mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-11 18:00:26 +00:00
initial pass at static export macros
This commit is contained in:
parent
2db6cbed2d
commit
4049affb31
@ -35,7 +35,8 @@ Command.prototype.execute = function() {
|
|||||||
wiki = this.commander.wiki,
|
wiki = this.commander.wiki,
|
||||||
filter = this.params[0],
|
filter = this.params[0],
|
||||||
template = this.params[1],
|
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",
|
type = this.params[3] || "text/html",
|
||||||
extension = this.params[4] || ".html",
|
extension = this.params[4] || ".html",
|
||||||
deleteDirectory = (this.params[5] || "") != "noclean",
|
deleteDirectory = (this.params[5] || "") != "noclean",
|
||||||
@ -43,14 +44,19 @@ Command.prototype.execute = function() {
|
|||||||
if(deleteDirectory){
|
if(deleteDirectory){
|
||||||
$tw.utils.deleteDirectory(pathname);
|
$tw.utils.deleteDirectory(pathname);
|
||||||
}
|
}
|
||||||
$tw.utils.createDirectory(pathname);
|
|
||||||
$tw.utils.each(tiddlers,function(title) {
|
$tw.utils.each(tiddlers,function(title) {
|
||||||
var parser = wiki.parseTiddler(template),
|
var parser = wiki.parseTiddler(template),
|
||||||
widgetNode = wiki.makeWidget(parser,{variables: {currentTiddler: title}});
|
widgetNode = wiki.makeWidget(parser,{variables: {currentTiddler: title}});
|
||||||
var container = $tw.fakeDocument.createElement("div");
|
var container = $tw.fakeDocument.createElement("div");
|
||||||
widgetNode.render(container,null);
|
widgetNode.render(container,null);
|
||||||
var text = type === "text/html" ? container.innerHTML : container.textContent;
|
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 = $tw.macros["tv-get-export-path"].run.apply(self,[title]);
|
||||||
|
}
|
||||||
|
var final_path = path.resolve(outputPath,(export_path || encodeURIComponent(title)) + extension);
|
||||||
|
$tw.utils.createDirectory(path.dirname(final_path));
|
||||||
|
fs.writeFileSync(final_path,text,"utf8");
|
||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
@ -76,7 +76,7 @@ LinkWidget.prototype.renderLink = function(parent,nextSibling) {
|
|||||||
var wikiLinkTemplateMacro = this.getVariable("tv-wikilink-template"),
|
var wikiLinkTemplateMacro = this.getVariable("tv-wikilink-template"),
|
||||||
wikiLinkTemplate = wikiLinkTemplateMacro ? wikiLinkTemplateMacro.trim() : "#$uri_encoded$",
|
wikiLinkTemplate = wikiLinkTemplateMacro ? wikiLinkTemplateMacro.trim() : "#$uri_encoded$",
|
||||||
wikiLinkText = wikiLinkTemplate.replace("$uri_encoded$",encodeURIComponent(this.to));
|
wikiLinkText = wikiLinkTemplate.replace("$uri_encoded$",encodeURIComponent(this.to));
|
||||||
wikiLinkText = wikiLinkText.replace("$uri_doubleencoded$",encodeURIComponent(encodeURIComponent(this.to)));
|
wikiLinkText = this.getVariable("tv-get-export-link") || wikiLinkText.replace("$uri_doubleencoded$",encodeURIComponent(encodeURIComponent(this.to)));
|
||||||
domNode.setAttribute("href",wikiLinkText);
|
domNode.setAttribute("href",wikiLinkText);
|
||||||
// Set the tooltip
|
// Set the tooltip
|
||||||
// HACK: Performance issues with re-parsing the tooltip prevent us defaulting the tooltip to "<$transclude field='tooltip'><$transclude field='title'/></$transclude>"
|
// HACK: Performance issues with re-parsing the tooltip prevent us defaulting the tooltip to "<$transclude field='tooltip'><$transclude field='title'/></$transclude>"
|
||||||
|
Loading…
Reference in New Issue
Block a user