mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-10-31 23:26:18 +00:00
305617b632
Allows us to save tiddlers in their raw format.
54 lines
1.3 KiB
JavaScript
54 lines
1.3 KiB
JavaScript
/*\
|
|
title: $:/core/modules/commands/savetiddlers.js
|
|
type: application/javascript
|
|
module-type: command
|
|
|
|
Command to save several tiddlers to a folder of files
|
|
|
|
\*/
|
|
(function(){
|
|
|
|
/*jslint node: true, browser: true */
|
|
/*global $tw: false */
|
|
"use strict";
|
|
|
|
var widget = require("$:/core/modules/widgets/widget.js");
|
|
|
|
exports.info = {
|
|
name: "savetiddlers",
|
|
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 filename";
|
|
}
|
|
var self = this,
|
|
fs = require("fs"),
|
|
path = require("path"),
|
|
wiki = this.commander.wiki,
|
|
filter = this.params[0],
|
|
pathname = path.resolve(this.commander.outputPath,this.params[1]),
|
|
tiddlers = wiki.filterTiddlers(filter);
|
|
$tw.utils.deleteDirectory(pathname);
|
|
$tw.utils.createDirectory(pathname);
|
|
$tw.utils.each(tiddlers,function(title) {
|
|
var tiddler = self.commander.wiki.getTiddler(title),
|
|
type = tiddler.fields.type || "text/vnd.tiddlywiki",
|
|
contentTypeInfo = $tw.config.contentTypeInfo[type] || {encoding: "utf8"},
|
|
filename = path.resolve(pathname,encodeURIComponent(title));
|
|
fs.writeFileSync(filename,tiddler.fields.text,contentTypeInfo.encoding);
|
|
});
|
|
return null;
|
|
};
|
|
|
|
exports.Command = Command;
|
|
|
|
})();
|