-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-rss.ts
36 lines (31 loc) · 1.09 KB
/
create-rss.ts
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
/* eslint @typescript-eslint/no-var-requires: 0 */
// If Vercel updates NodeJS, then we can use ESM modules
import { readdirSync, writeFileSync } from 'fs';
import RSS from 'rss';
const directory = './.contentlayer/generated/Post';
const files = readdirSync(directory);
const allPosts = [];
// Now dynamically import all the posts from the files in the generated folder
for (const file of files) {
const jsonObject = require(directory + '/' + file);
// const { default: jsonObject } = await import(directory + '/' + file, { assert: { type: 'json' } });
allPosts.push(jsonObject);
}
const feed = new RSS({
title: 'imjes.se Blog',
webMaster: 'Jesse van der Velden',
feed_url: 'https://imjes.se/rss.xml',
site_url: 'https://imjes.se',
language: 'en',
});
allPosts
.map((post) => ({
title: post.title,
description: post.excerpt,
categories: post.tags,
url: `https://imjes.se/blog/${post.slug}`,
date: new Date(post.date),
author: post.author ?? 'Jesse van der Velden',
}))
.forEach((item) => feed.item(item));
writeFileSync('./public/rss.xml', feed.xml({ indent: true }));