-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathgenerate-rss-feed.mjs
More file actions
66 lines (58 loc) · 2.12 KB
/
generate-rss-feed.mjs
File metadata and controls
66 lines (58 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import fs from 'fs';
import RSS from 'rss';
import { blogpostsDetails } from '../src/components/blog/blogpostsDetails.js';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const outputDir = path.join(__dirname, '../static');
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
const generateFeedFromBlogDetails = (feed, blogpostsDetails, nbOfBlogPosts) => {
let posts = [];
for (let i = 0; i < nbOfBlogPosts; i++) {
const post = blogpostsDetails[i];
posts.push({
title: post.title,
description: post.summary,
date: post.date,
authors: post.authors,
url: post.url,
image: post.image,
})
};
posts.forEach((post) => {
feed.item({
title: post.title,
description: post.description,
url: post.url,
date: post.date,
author: post.authors,
enclosure: {
url: 'https://quantstack.net' + post.image,
type: 'image/png',
length: 0,
},
});
});
return feed;
}
const feedLast20 = new RSS({
title: 'Recent blog posts featured by QuantStack team',
description: 'RSS feed for QuantStack website blog page',
feed_url: 'https://quantstack.net/rss.xml',
site_url: 'https://quantstack.net',
language: 'en',
});
const updatedFeedLast20 = generateFeedFromBlogDetails(feedLast20, blogpostsDetails, 20);
fs.writeFileSync(path.join(outputDir, 'rss.xml'), updatedFeedLast20.xml({ indent: true }));
const feedAll = new RSS({
title: 'All blog posts featured by QuantStack team',
description: 'RSS feed for QuantStack website blog page',
feed_url: 'https://quantstack.net/rss_all.xml',
site_url: 'https://quantstack.net',
language: 'en',
});
const updatedFeedAll = generateFeedFromBlogDetails(feedAll, blogpostsDetails, blogpostsDetails.length)
fs.writeFileSync(path.join(outputDir, 'rss_all.xml'), updatedFeedAll.xml({ indent: true }));