mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-01-26 21:03:42 +00:00
Revert to using parameterised paths instead of filters
Because we will be able to run parameterised paths in reverse for HTTP serving, which we can't do with filters
This commit is contained in:
@@ -149,23 +149,23 @@ PublishingJob.prototype.getOperationsForRoute = function(routeTiddler) {
|
||||
if(routeFilter) {
|
||||
switch(routeTiddler.fields["route-type"]) {
|
||||
case "save":
|
||||
if(routeTiddler.fields["route-path-filter"]) {
|
||||
if(routeTiddler.fields["route-path"]) {
|
||||
$tw.utils.each(tiddlers,function(title) {
|
||||
operations.push({
|
||||
"route-type": "save",
|
||||
path: self.resolvePathFilter(routeTiddler.fields["route-path-filter"],title),
|
||||
path: self.resolveParameterisedPath(routeTiddler.fields["route-path"],title),
|
||||
title: title
|
||||
});
|
||||
});
|
||||
}
|
||||
break;
|
||||
case "render":
|
||||
if(routeTiddler.fields["route-path-filter"] && routeTiddler.fields["route-template"]) {
|
||||
if(routeTiddler.fields["route-path"] && routeTiddler.fields["route-template"]) {
|
||||
var routeVariables = $tw.utils.extend({},this.publishVariables,this.jobVariables,this.sitemapVariables,this.extractVariables(routeTiddler));
|
||||
$tw.utils.each(tiddlers,function(title) {
|
||||
operations.push({
|
||||
"route-type": "render",
|
||||
path: self.resolvePathFilter(routeTiddler.fields["route-path-filter"],title),
|
||||
path: self.resolveParameterisedPath(routeTiddler.fields["route-path"],title),
|
||||
title: title,
|
||||
template: routeTiddler.fields["route-template"],
|
||||
variables: routeVariables
|
||||
@@ -179,22 +179,48 @@ PublishingJob.prototype.getOperationsForRoute = function(routeTiddler) {
|
||||
};
|
||||
|
||||
/*
|
||||
Apply a tiddler to a filter to create a usable path
|
||||
Apply a tiddler to a parameterised path to create a usable path
|
||||
*/
|
||||
PublishingJob.prototype.resolvePathFilter = function(pathFilter,title) {
|
||||
var tiddler = this.publisherHandler.wiki.getTiddler(title);
|
||||
return this.publisherHandler.wiki.filterTiddlers(pathFilter,{
|
||||
getVariable: function(name) {
|
||||
switch(name) {
|
||||
case "currentTiddler":
|
||||
return "" + this.imageSource;
|
||||
case "extension":
|
||||
return "" + ($tw.config.contentTypeInfo[tiddler.fields.type || "text/vnd.tiddlywiki"] || {extension: ""}).extension;
|
||||
default:
|
||||
return $tw.rootWidget.getVariable(name);
|
||||
PublishingJob.prototype.resolveParameterisedPath = function(route,title) {
|
||||
var self = this;
|
||||
// Split the route on $$ markers
|
||||
var tiddler = this.publisherHandler.wiki.getTiddler(title),
|
||||
output = [];
|
||||
$tw.utils.each(route.split(/(\$[a-z_]+\$)/),function(part) {
|
||||
var match = part.match(/\$([a-z]+)_([a-z]+)\$/);
|
||||
if(match) {
|
||||
var value;
|
||||
// Get the base value
|
||||
switch(match[1]) {
|
||||
case "uri":
|
||||
case "title":
|
||||
value = title;
|
||||
break;
|
||||
case "type":
|
||||
value = tiddler.fields.type || "text/vnd.tiddlywiki";
|
||||
break;
|
||||
}
|
||||
// Apply the encoding function
|
||||
switch(match[2]) {
|
||||
case "encoded":
|
||||
value = encodeURIComponent(value);
|
||||
break;
|
||||
case "doubleencoded":
|
||||
value = encodeURIComponent(encodeURIComponent(value));
|
||||
break;
|
||||
case "slugify":
|
||||
value = self.publisherHandler.wiki.slugify(value);
|
||||
break;
|
||||
case "extension":
|
||||
value = ($tw.config.contentTypeInfo[value] || {extension: "."}).extension.slice(1);
|
||||
break;
|
||||
}
|
||||
output.push(value);
|
||||
} else {
|
||||
output.push(part);
|
||||
}
|
||||
},this.publisherHandler.wiki.makeTiddlerIterator([title]))[0];
|
||||
});
|
||||
return output.join("");
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
@@ -56,7 +56,7 @@ Logs: <$view tiddler=<<job>> field="list"/>
|
||||
|
||||
job-type: <$view tiddler=<<route>> field="route-type"/>
|
||||
|
||||
path: <$edit-text tiddler=<<route>> size="50" field="route-path-filter"/>
|
||||
path: <$edit-text tiddler=<<route>> size="50" field="route-path"/>
|
||||
|
||||
filter: <$edit-text tiddler=<<route>> size="50" field="route-tiddler-filter"/>
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
title: $:/config/PublishingJobs/Default
|
||||
tags: $:/tags/PublishingJob
|
||||
caption: Demo static site
|
||||
publisher: jszip
|
||||
publisher: filesystem
|
||||
sitemap: $:/core/sitemaps/StaticSite
|
||||
jszip-output-filename: myzipfile.zip
|
||||
baseurl: https://example.com
|
||||
|
||||
@@ -2,6 +2,6 @@ title: $:/core/routes/StaticSite/HTML
|
||||
caption: Static HTML
|
||||
tags: $:/tags/Route
|
||||
route-type: render
|
||||
route-path-filter: [addprefix[static/]addsuffix[.html]]
|
||||
route-path: static/$title_slugify$.html
|
||||
route-tiddler-filter: [!is[system]!is[image]]
|
||||
route-template: $:/core/templates/static.tiddler.html
|
||||
|
||||
@@ -2,5 +2,5 @@ title: $:/core/routes/StaticSite/Images
|
||||
caption: Images
|
||||
tags: $:/tags/Route
|
||||
route-type: save
|
||||
route-path-filter: [slugify[]addprefix[images/]addsuffix<extension>]
|
||||
route-path: images/$title_slugify$.$type_extension$
|
||||
route-tiddler-filter: [is[image]]
|
||||
|
||||
@@ -2,5 +2,5 @@ title: $:/core/routes/StaticSite/Index
|
||||
caption: Index
|
||||
tags: $:/tags/Route
|
||||
route-type: render
|
||||
route-path-filter: index.html
|
||||
route-path: index.html
|
||||
route-template: $:/core/save/all
|
||||
|
||||
@@ -2,5 +2,5 @@ title: $:/core/routes/StaticSite/Styles
|
||||
caption: Styles
|
||||
tags: $:/tags/Route
|
||||
route-type: render
|
||||
route-path-filter: static/static.css
|
||||
route-path: static/static.css
|
||||
route-template: $:/core/templates/static.template.css
|
||||
|
||||
@@ -50,7 +50,7 @@ A ''route'' describes how a group of one or more files is to be created during t
|
||||
* ''caption'' -- human readable short name for the route
|
||||
* ''tags'' -- `$:/tags/Route`
|
||||
* ''route-tiddler-filter'' -- a filter defining the tiddlers included in the route
|
||||
* ''route-path-filter'' - a filter defining how the ''output path'' is derived from the field values of a particular tiddler
|
||||
* ''route-path'' - a parameterised path defining how the ''output path'' is derived from the field values of a particular tiddler
|
||||
* ''route-template'' -- optional title of a tiddler used as a template for "render" route types
|
||||
* ''route-type'' which can be set to "save" or "render":
|
||||
** ''"save"'' indicates that the raw tiddler is to be saved, without any rendering
|
||||
@@ -58,3 +58,12 @@ A ''route'' describes how a group of one or more files is to be created during t
|
||||
* ''var-<variable-name>'' -- custom variables to be provided to the output template
|
||||
|
||||
The route tiddler filter is passed the tiddlers resulting from the job export filter. In order to respect the restrictions of the job export filter, route filters must be carefully constructed to ensure they pull their titles from the incoming list.
|
||||
|
||||
Parameterised paths are strings which may contain optional tokens of the format `fieldname_functionname`. These tokens are replaced by the value of the specified field passed through the specified encoding function. The available encoding functions are:
|
||||
|
||||
* ''encoded'' -- applies URI encoding to the value
|
||||
* ''doubleencoded'' -- applies double URI encoding to the value
|
||||
* ''slugify'' -- applies the [[slugify Operator]] to the value
|
||||
* ''extension'' -- interprets the value as a content type and returns the associated file extension
|
||||
|
||||
For backwards compatibility, the field "uri" is accepted as a synonym for "title".
|
||||
Reference in New Issue
Block a user