diff --git a/core/modules/publisher-handler.js b/core/modules/publisher-handler.js index 43319a26a..a54927654 100644 --- a/core/modules/publisher-handler.js +++ b/core/modules/publisher-handler.js @@ -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(""); }; /* diff --git a/core/ui/ControlPanel/Publishing.tid b/core/ui/ControlPanel/Publishing.tid index 68492dfc5..4f1d55f6b 100644 --- a/core/ui/ControlPanel/Publishing.tid +++ b/core/ui/ControlPanel/Publishing.tid @@ -56,7 +56,7 @@ Logs: <$view tiddler=<> field="list"/> job-type: <$view tiddler=<> field="route-type"/> -path: <$edit-text tiddler=<> size="50" field="route-path-filter"/> +path: <$edit-text tiddler=<> size="50" field="route-path"/> filter: <$edit-text tiddler=<> size="50" field="route-tiddler-filter"/> diff --git a/core/wiki/publishing-jobs/Default.tid b/core/wiki/publishing-jobs/Default.tid index 179e935aa..43265b9c7 100644 --- a/core/wiki/publishing-jobs/Default.tid +++ b/core/wiki/publishing-jobs/Default.tid @@ -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 diff --git a/core/wiki/routes/StaticSite/HTML.tid b/core/wiki/routes/StaticSite/HTML.tid index f7fef58be..11a3e0cca 100644 --- a/core/wiki/routes/StaticSite/HTML.tid +++ b/core/wiki/routes/StaticSite/HTML.tid @@ -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 diff --git a/core/wiki/routes/StaticSite/Images.tid b/core/wiki/routes/StaticSite/Images.tid index 998d1e20b..c27bccf52 100644 --- a/core/wiki/routes/StaticSite/Images.tid +++ b/core/wiki/routes/StaticSite/Images.tid @@ -2,5 +2,5 @@ title: $:/core/routes/StaticSite/Images caption: Images tags: $:/tags/Route route-type: save -route-path-filter: [slugify[]addprefix[images/]addsuffix] +route-path: images/$title_slugify$.$type_extension$ route-tiddler-filter: [is[image]] diff --git a/core/wiki/routes/StaticSite/Index.tid b/core/wiki/routes/StaticSite/Index.tid index 60a9281b2..61f551934 100644 --- a/core/wiki/routes/StaticSite/Index.tid +++ b/core/wiki/routes/StaticSite/Index.tid @@ -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 diff --git a/core/wiki/routes/StaticSite/Styles.tid b/core/wiki/routes/StaticSite/Styles.tid index 91ef47c7d..66b4a5ead 100644 --- a/core/wiki/routes/StaticSite/Styles.tid +++ b/core/wiki/routes/StaticSite/Styles.tid @@ -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 diff --git a/editions/tw5.com/tiddlers/publishing/Publishing.tid b/editions/tw5.com/tiddlers/publishing/Publishing.tid index 93d903db6..bede9251a 100644 --- a/editions/tw5.com/tiddlers/publishing/Publishing.tid +++ b/editions/tw5.com/tiddlers/publishing/Publishing.tid @@ -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". \ No newline at end of file