-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen-rss.js
39 lines (33 loc) · 1.08 KB
/
gen-rss.js
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
const { promises: fs } = require("fs");
const path = require("path");
const { Feed } = require("feed");
const matter = require("gray-matter");
const { marked } = require("marked");
async function generate() {
const feed = new Feed({
title: "Loro Changelog",
description: "changelog of loro crdt",
link: "https://loro.dev",
feedLinks: "https://loro.dev/changelog.xml",
});
const posts = await fs.readdir(path.join(__dirname, "pages", "changelog"));
await Promise.all(
posts.map(async (name) => {
if (name.endsWith(".json")) return;
const content = await fs.readFile(
path.join(__dirname, "pages", "changelog", name)
);
const frontmatter = matter(content);
const html = marked.parse(frontmatter.content);
feed.addItem({
title: frontmatter.data.title,
link: "/changelog/" + name.replace(/\.mdx?/, ""),
date: new Date(frontmatter.data.date),
content: html,
});
})
);
await fs.writeFile("./public/changelog.xml", feed.rss2());
console.log("generated changelog.xml");
}
generate();