Skip to content

Commit 2239156

Browse files
committed
Add: RSS feed for blogs
1 parent 3964b7a commit 2239156

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

package-lock.json

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"remark-autolink-headings": "^6.0.1",
4747
"remark-code-titles": "^0.1.1",
4848
"remark-slug": "^6.0.0",
49+
"rss": "^1.2.2",
4950
"swr": "^0.5.3"
5051
},
5152
"devDependencies": {

pages/feed.xml.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { getAllFilesFrontMatter } from "@/lib/mdx";
2+
import RSS from "rss";
3+
4+
export async function getServerSideProps({ res }) {
5+
const feed = new RSS({
6+
title: "Manu Arora",
7+
site_url: "https://manuarora.in",
8+
feed_url: "https://leerob.io/feed.xml",
9+
});
10+
11+
const posts = await getAllFilesFrontMatter("blog");
12+
const filteredBlogPosts = posts.sort(
13+
(a, b) => Number(new Date(b.publishedAt)) - Number(new Date(a.publishedAt))
14+
);
15+
filteredBlogPosts.map((post) => {
16+
feed.item({
17+
title: post.title,
18+
url: `https://manuarora.in/blog/${post.slug}`,
19+
date: post.publishedAt,
20+
description: post.summary,
21+
});
22+
});
23+
24+
res.setHeader("Content-Type", "text/xml");
25+
res.setHeader(
26+
"Cache-Control",
27+
"public, s-maxage=1200, stale-while-revalidate=600"
28+
);
29+
res.write(feed.xml({ indent: true }));
30+
res.end();
31+
32+
return {
33+
props: {},
34+
};
35+
}
36+
37+
export default function RSSFeed() {
38+
return null;
39+
}

public/sitemap.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
<loc>https://manuarora.in/dashboard</loc>
1313
</url>
1414

15+
<url>
16+
<loc>https://manuarora.in/feed.xml</loc>
17+
</url>
18+
1519
<url>
1620
<loc>https://manuarora.in/freecodecamp</loc>
1721
</url>

0 commit comments

Comments
 (0)