kopia lustrzana https://github.com/miklobit/TiddlyWiki5
Introduce savetiddlers command
Allows us to save tiddlers in their raw format.print-window-tiddler
rodzic
b446ef5d4e
commit
305617b632
|
@ -0,0 +1,12 @@
|
|||
title: $:/language/Help/savetiddlers
|
||||
description: Saves a raw tiddler to a file
|
||||
|
||||
Saves a group of tiddlers in their raw text or binary format to the specified directory.
|
||||
|
||||
```
|
||||
--savetiddlers <filter> <pathname>
|
||||
```
|
||||
|
||||
By default, the filename is resolved relative to the `output` subdirectory of the edition directory. The `--output` command can be used to direct output to a different directory.
|
||||
|
||||
Any missing directories in the pathname are automatically created.
|
|
@ -0,0 +1,53 @@
|
|||
/*\
|
||||
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;
|
||||
|
||||
})();
|
|
@ -0,0 +1,6 @@
|
|||
title: SaveTiddlersCommand
|
||||
tags: command
|
||||
created: 20140609121606089
|
||||
modified: 20140609121606089
|
||||
|
||||
{{$:/language/Help/savetiddler}}
|
Ładowanie…
Reference in New Issue