diff options
| author | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2021-03-20 23:40:24 +0100 |
|---|---|---|
| committer | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2021-03-20 23:40:24 +0100 |
| commit | 9e355758760cfa0c3d34759d22875c9d82ddd971 (patch) | |
| tree | 5159301f70a1e52d696683643d2046260f1a931c /lib | |
| parent | 4aa5845077d5cb5153b8095726d747bd1eabb48c (diff) | |
Add title to html/rss generators
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/generators/html.js | 7 | ||||
| -rw-r--r-- | lib/generators/rss.js | 17 |
2 files changed, 17 insertions, 7 deletions
diff --git a/lib/generators/html.js b/lib/generators/html.js index ba2676c..9579cb2 100644 --- a/lib/generators/html.js +++ b/lib/generators/html.js @@ -1,6 +1,6 @@ 'use strict'; -const { template } = require('dot'); +const { template, templateSettings } = require('dot'); const { readFile, writeFile } = require('fs/promises'); const { join } = require('path'); const { debuglog } = require('util'); @@ -29,7 +29,10 @@ module.exports = async function HTMLGenerator(source, target, posts) { const indexTemplate = await readFile(indexLocation, { encoding: 'utf8' }); internals.debuglog('Writing HTML'); - const indexHtml = template(indexTemplate)({ posts }); + const indexHtml = template(indexTemplate, { + ...templateSettings, + strip: false + })({ posts }); await writeFile(indexTarget, indexHtml); }; diff --git a/lib/generators/rss.js b/lib/generators/rss.js index a1fcb08..ec45dc8 100644 --- a/lib/generators/rss.js +++ b/lib/generators/rss.js @@ -1,6 +1,6 @@ 'use strict'; -const { template } = require('dot'); +const { template, templateSettings } = require('dot'); const { encodeXML } = require('entities'); const { readFile, writeFile } = require('fs/promises'); const { join } = require('path'); @@ -9,7 +9,12 @@ const { debuglog } = require('util'); const internals = { debuglog: debuglog('blog'), - kFeedName: 'feed.xml' + kFeedName: 'feed.xml', + + extractTitle(postText) { + + return postText.trim().split('\n')[0].replace('#', '').trim(); + } }; /** @@ -33,10 +38,12 @@ module.exports = async function RSSGenerator(source, target, posts) { posts = posts.map((post) => ({ ...post, createdOn: (new Date(post.createdOn)).toUTCString(), + title: internals.extractTitle(post.raw), html: encodeXML(post.html) })); - const feedXml = template(feedTemplate)({ posts }); + const feedXml = template(feedTemplate, { + ...templateSettings, + strip: false + })({ posts }); await writeFile(feedTarget, feedXml); }; - - |