]>
git.r.bdr.sh - rbdr/blog/blob - lib/generators/rss.js
a1fcb0801ed7c3a2db8551f62f6d9644889a1df9
3 const { template
} = require('dot');
4 const { encodeXML
} = require('entities');
5 const { readFile
, writeFile
} = require('fs/promises');
6 const { join
} = require('path');
7 const { debuglog
} = require('util');
10 debuglog: debuglog('blog'),
16 * Generates an RSS feed XML file
19 * @param {string} source the source directory
20 * @param {string} target the target directory
21 * @param {Array.<Blog.tPost>} posts the list of posts
23 module
.exports
= async
function RSSGenerator(source
, target
, posts
) {
25 internals
.debuglog('Generating RSS');
26 const feedTarget
= join(target
, internals
.kFeedName
);
27 const feedLocation
= join(source
, internals
.kFeedName
);
29 internals
.debuglog(`Reading ${feedLocation}`);
30 const feedTemplate
= await
readFile(feedLocation
, { encoding: 'utf8' });
32 internals
.debuglog('Writing RSS');
33 posts
= posts
.map((post
) => ({
35 createdOn: (new Date(post
.createdOn
)).toUTCString(),
36 html: encodeXML(post
.html
)
38 const feedXml
= template(feedTemplate
)({ posts
});
39 await
writeFile(feedTarget
, feedXml
);