2017-09-12 15:04:07 +00:00
|
|
|
/*\
|
|
|
|
title: $:/core/modules/commands/render.js
|
|
|
|
type: application/javascript
|
|
|
|
module-type: command
|
|
|
|
|
|
|
|
Render individual tiddlers and save the results to the specified files
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
2021-09-24 17:40:34 +00:00
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var widget = require("$:/core/modules/widgets/widget.js");
|
|
|
|
|
|
|
|
exports.info = {
|
|
|
|
name: "render",
|
|
|
|
synchronous: true
|
|
|
|
};
|
|
|
|
|
|
|
|
var Command = function(params,commander,callback) {
|
|
|
|
this.params = params;
|
|
|
|
this.commander = commander;
|
|
|
|
this.callback = callback;
|
|
|
|
};
|
|
|
|
|
|
|
|
Command.prototype.execute = function() {
|
|
|
|
if(this.params.length < 1) {
|
|
|
|
return "Missing tiddler filter";
|
2017-09-12 15:04:07 +00:00
|
|
|
}
|
2021-09-24 17:40:34 +00:00
|
|
|
var self = this,
|
|
|
|
fs = require("fs"),
|
|
|
|
path = require("path"),
|
|
|
|
wiki = this.commander.wiki,
|
|
|
|
tiddlerFilter = this.params[0],
|
|
|
|
filenameFilter = this.params[1] || "[is[tiddler]addsuffix[.html]]",
|
|
|
|
type = this.params[2] || "text/html",
|
|
|
|
template = this.params[3],
|
|
|
|
variableList = this.params.slice(4),
|
|
|
|
tiddlers = wiki.filterTiddlers(tiddlerFilter),
|
|
|
|
variables = Object.create(null);
|
|
|
|
while(variableList.length >= 2) {
|
|
|
|
variables[variableList[0]] = variableList[1];
|
|
|
|
variableList = variableList.slice(2);
|
|
|
|
}
|
|
|
|
$tw.utils.each(tiddlers,function(title) {
|
|
|
|
var filepath = path.resolve(self.commander.outputPath,wiki.filterTiddlers(filenameFilter,$tw.rootWidget,wiki.makeTiddlerIterator([title]))[0]);
|
|
|
|
if(self.commander.verbose) {
|
2024-06-07 17:09:50 +00:00
|
|
|
console.log("Rendering \"" + title + "\" to \"" + filepath + "\"");
|
2021-09-24 17:40:34 +00:00
|
|
|
}
|
|
|
|
var parser = wiki.parseTiddler(template || title),
|
2022-06-29 07:58:40 +00:00
|
|
|
widgetNode = wiki.makeWidget(parser,{variables: $tw.utils.extend({},variables,{currentTiddler: title,storyTiddler: title})}),
|
2021-09-24 17:40:34 +00:00
|
|
|
container = $tw.fakeDocument.createElement("div");
|
|
|
|
widgetNode.render(container,null);
|
|
|
|
var text = type === "text/html" ? container.innerHTML : container.textContent;
|
|
|
|
$tw.utils.createFileDirectories(filepath);
|
|
|
|
fs.writeFileSync(filepath,text,"utf8");
|
|
|
|
});
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.Command = Command;
|
|
|
|
|
|
|
|
})();
|
2024-06-07 17:09:50 +00:00
|
|
|
|