mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-02-02 20:29:10 +00:00
Introduce savetiddlers command
Allows us to save tiddlers in their raw format.
This commit is contained in:
parent
b446ef5d4e
commit
305617b632
12
core/language/en-GB/Help/savetiddlers.tid
Normal file
12
core/language/en-GB/Help/savetiddlers.tid
Normal file
@ -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.
|
53
core/modules/commands/savetiddlers.js
Normal file
53
core/modules/commands/savetiddlers.js
Normal file
@ -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}}
|
Loading…
Reference in New Issue
Block a user