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