1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-26 07:13:15 +00:00

Add support for static site generation

See http://five.tiddlywiki.com/static.html for an example
This commit is contained in:
Jeremy Ruston 2013-03-04 18:15:54 +00:00
parent c24c00e8d6
commit 15a9e04a6a
8 changed files with 142 additions and 1 deletions

5
bld.sh
View File

@ -19,6 +19,10 @@ echo "Using TW5_BUILD_OUTPUT as [$TW5_BUILD_OUTPUT]"
echo "five.tiddlywiki.com" > $TW5_BUILD_OUTPUT/CNAME
# Create the `static` directory if necessary
mkdir -p $TW5_BUILD_OUTPUT/static
# First,
# readme.md: the readme file for GitHub
# index.html: the main file, including content
@ -30,6 +34,7 @@ node ./tiddlywiki.js \
--savetiddler ReadMe ./readme.md text/html \
--savetiddler $:/core/templates/tiddlywiki5.template.html $TW5_BUILD_OUTPUT/index.html text/plain \
--savetiddler $:/core/templates/static.template.html $TW5_BUILD_OUTPUT/static.html text/plain \
--savetiddlers [!is[shadow]] $:/core/templates/static.tiddler.html $TW5_BUILD_OUTPUT/static text/plain \
|| exit 1
# Second, encrypted.html: a version of the main file encrypted with the password "password"

View File

@ -0,0 +1,54 @@
/*\
title: $:/core/modules/commands/savetiddlers.js
type: application/javascript
module-type: command
Command to save several tiddlers to a file
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports.info = {
name: "savetiddlers",
synchronous: false
};
var Command = function(params,commander,callback) {
this.params = params;
this.commander = commander;
this.callback = callback;
};
Command.prototype.execute = function() {
if(this.params.length < 2) {
return "Missing filename";
}
var self = this,
fs = require("fs"),
path = require("path"),
wiki = this.commander.wiki,
filter = this.params[0],
template = this.params[1],
pathname = this.params[2],
type = this.params[3] || "text/html",
extension = this.params[4] || ".html",
parser = wiki.parseTiddler(template),
tiddlers = wiki.filterTiddlers(filter);
$tw.utils.each(tiddlers,function(title) {
var renderTree = new $tw.WikiRenderTree(parser,{wiki: wiki});
renderTree.execute({tiddlerTitle: title});
var text = renderTree.render(type);
fs.writeFile(path.resolve(pathname,title + extension),text,"utf8",function(err) {
self.callback(err);
});
});
return null;
};
exports.Command = Command;
})();

View File

@ -1,12 +1,13 @@
title: $:/core/templates/static.template.html
type: text/vnd.tiddlywiki-html
\define tw-wikilink-template() static/$uri_encoded$.html
\rules only filteredtranscludeinline transcludeinline
<!doctype html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="generator" content="TiddlyWiki" />
<meta name="tiddlywiki-version" content="{{version}}" />
<meta name="tiddlywiki-version" content="{{$:/core/templates/version}}" />
<meta name="format-detection" content="telephone=no">
<meta name="copyright" content="{{$:/core/copyright.txt}}" />
<title>{{$:/core/wiki/title}}</title>

View File

@ -0,0 +1,36 @@
title: $:/core/templates/static.tiddler.html
\define tw-wikilink-template() $uri_encoded$.html
`<!doctype html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="generator" content="TiddlyWiki" />
<meta name="tiddlywiki-version" content="`{{$:/core/templates/version}}`" />
<meta name="format-detection" content="telephone=no">
<meta name="copyright" content="`{{$:/core/copyright.txt}}`" />
<title>`{{$:/core/wiki/title}}`</title>
<div id="styleArea">
`{{{ [is[shadow]type[text/css]] ||$:/core/templates/css-tiddler}}}`
</div>
<style type="text/css">
`{{$:/core/styles/base}}`
</style>
</head>
<body>
<section class="story-river">
<div class="tw-tiddler-frame">
<span class="title">
`<$view field="title"/>`
</span>
<div class="small">`<$view field="modifier" format="link"/>` `<$view field="modified" format="date"/>`</div>
<div class="tw-tags-wrapper">`<$list filter="[is[current]tags[]]" template="$:/templates/TagTemplate" />`</div>
<div class="body">
`<$transclude template="$:/core/templates/html-tiddler" />`
</div>
</div>
</section>
</body>
</html>
`

View File

@ -5,6 +5,7 @@ The core TiddlyWiki5 code is packaged into several distinct editions designed fo
* [[TiddlyWiki5 Standalone Edition]] for working purely within the browser
** Including [[TiddlyWiki5 in the Sky for TiddlySpot|TiddlySpot]]
** And incorporating [[TiddlyWiki5 Static Site Generation]]
* [[TiddlyWiki5 Node Edition]] for advanced command line work
** Including [[Building classic TiddlyWiki with TiddlyWiki5]]
* [[TiddlyWiki5 in the Sky for TiddlyWeb]] (and TiddlySpace)

View File

@ -0,0 +1,14 @@
title: SaveTiddlersCommand
tags: docs command
Save a set of tiddlers matching a filter as separate files of a specified ContentType (defaults to `text/html`) and extension (defaults to `.html`).
```
--savetiddlers <filter> <template> <pathname> [<type>] [<extension>]
```
For example:
```
--savetiddlers [!is[shadow]] $:/core/templates/static.tiddler.html ./static text/plain
```

View File

@ -0,0 +1,16 @@
title: TiddlyWiki5 Static Site Generation
tags: edition docs
TiddlyWiki5 can be used to generate a static HTML representation of a TiddlyWiki that doesn't need JavaScript.
! Example
You can explore a static representation of the TiddlyWiki5 site at <a href="static.html">static.html</a>. That file is a static representation of the current DefaultTiddlers. Any tiddlers that it links to are referred to via URLs of the form `/static/HelloThere.html` that point to HTML representations of individual tiddlers.
The included `bld.sh` script includes these commands that are involved in generating the sample static version of the TiddlyWiki5 site:
```
--savetiddler $:/core/templates/static.template.html $TW5_BUILD_OUTPUT/static.html text/plain \
--savetiddlers [!is[shadow]] $:/core/templates/static.tiddler.html $TW5_BUILD_OUTPUT/static text/plain \
```
The SaveTiddlerCommand saves the static version of the DefaulTiddlers and the SaveTiddlersCommand generates the HTML representations of individual tiddlers.

View File

@ -105,6 +105,20 @@ text/html</code> </p><pre>
<h3 class=''>
<span class='tw-view-link'>
<span>
SaveTiddlersCommand</span></span></h3><div>
<div class='tw-transclude'>
<p>
Save a set of tiddlers matching a filter as separate files of a specified <span>
ContentType</span> (defaults to <code>
text/html</code>) and extension (defaults to <code>
.html</code>).</p><pre>
--savetiddlers &lt;filter&gt; &lt;template&gt; &lt;pathname&gt; [&lt;type&gt;] [&lt;extension&gt;]</pre><p>
For example:</p><pre>
--savetiddlers [!is[shadow]] $:/core/templates/static.tiddler.html ./static text/plain</pre></div></div></span></div><div class='tw-list-element'>
<span class='tw-transclude'>
<h3 class=''>
<span class='tw-view-link'>
<span>
ServerCommand</span></span></h3><div>
<div class='tw-transclude'>
<p>