Created
April 13, 2021 02:31
-
-
Save arkmuntasser/7d73909b3c7d7cc8f61c915f1df1b65f to your computer and use it in GitHub Desktop.
Generate an RSS feed for a Next-MDX blog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const RSS = require('rss') | |
const { getAllNodes } = require('next-mdx'); | |
const feed = new RSS({ | |
title: 'My Blog', | |
site_url: 'https://my-blog.com' | |
}); | |
const posts = await getAllNodes('post'); | |
posts.forEach(post => { | |
feed.item({ | |
title: post.frontMatter.title, | |
guid: post.slug, | |
url: `https://my-blog.com/post/${post.url}`, | |
date: post.frontMatter.date | |
}); | |
}); | |
const xml = feed.xml({ indent: true }); | |
fx.writeFileSync('public/rss.xml', xml); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment