]>
git.r.bdr.sh - rbdr/blog/blob - lib/generators/rss.js
a46a394f1f6a1c74b4ab72fcc2edd1d5d1a38b3d
4 import { encodeXML
} from 'entities';
5 import { readFile
, writeFile
} from 'fs/promises';
6 import { join
} from 'path';
7 import { debuglog
} from 'util';
10 debuglog: debuglog('blog'),
12 kFeedName: 'feed.xml',
14 extractTitle(postText
) {
16 return postText
.trim()
19 .replace(/&/g
, '&')
25 * Generates an RSS feed XML file
28 * @param {string} source the source directory
29 * @param {string} target the target directory
30 * @param {Array.<Blog.tPost>} posts the list of posts
32 export default async
function RSSGenerator(source
, target
, posts
) {
34 internals
.debuglog('Generating RSS');
35 const feedTarget
= join(target
, internals
.kFeedName
);
36 const feedLocation
= join(source
, internals
.kFeedName
);
38 internals
.debuglog(`Reading ${feedLocation}`);
39 const feedTemplate
= await
readFile(feedLocation
, { encoding: 'utf8' });
41 internals
.debuglog('Writing RSS');
42 posts
= posts
.map((post
) => ({
44 createdOn: (new Date(post
.createdOn
)).toUTCString(),
45 title: internals
.extractTitle(post
.raw
),
46 html: encodeXML(post
.html
)
48 const feedXml
= Dot
.template(feedTemplate
, {
49 ...Dot
.templateSettings
,
52 await
writeFile(feedTarget
, feedXml
);