Skip to content

Commit

Permalink
Added RSS Feed solving leerob#525
Browse files Browse the repository at this point in the history
  • Loading branch information
z4nr34l committed Jul 11, 2023
1 parent 9d1036e commit 5bb0057
Show file tree
Hide file tree
Showing 4 changed files with 797 additions and 682 deletions.
30 changes: 30 additions & 0 deletions app/api/blog/feed.xml/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Rss from "rss";
import { allBlogs } from "contentlayer/generated";

const siteUrl = 'https://leerob.io';

export async function GET(request: Request) {
const feed = new Rss({
title: "Lee Robinson",
description: "Developer, writer, and creator.",
feed_url: `${siteUrl}/api/blog/feed.xml`,
site_url: siteUrl,
language: "en",
});

allBlogs.forEach((post) => {
feed.item({
title: post.title,
description: post.summary,
url: `${siteUrl}/blog/${post.slug}`,
date: post.publishedAt,
});
});

return new Response(feed.xml(), {
status: 200,
headers: {
'Content-Type': 'application/xml'
}
})
}
19 changes: 12 additions & 7 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ export const metadata: Metadata = {
google: 'eZSdmzAXlLkKhNJzfgwDqWORghxnJ8qR9_CHdAh5-xw',
yandex: '14d2e73487fa6c71',
},
alternates: {
types: {
'application/rss+xml': 'https://leerob.io/api/blog/feed.xml',
}
}
};

export default function RootLayout({
Expand All @@ -71,13 +76,13 @@ export default function RootLayout({
graphik.variable
)}
>
<body className="antialiased max-w-2xl mb-40 flex flex-col md:flex-row mx-4 mt-8 lg:mx-auto">
<main className="flex-auto min-w-0 mt-6 flex flex-col px-2 md:px-0">
<Sidebar />
{children}
<Analytics />
</main>
</body>
<body className="antialiased max-w-2xl mb-40 flex flex-col md:flex-row mx-4 mt-8 lg:mx-auto">
<main className="flex-auto min-w-0 mt-6 flex flex-col px-2 md:px-0">
<Sidebar/>
{children}
<Analytics/>
</main>
</body>
</html>
);
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"rehype-pretty-code": "^0.10.0",
"rehype-slug": "^5.1.0",
"remark-gfm": "^3.0.1",
"rss": "^1.2.2",
"server-only": "^0.0.1",
"shiki": "^0.14.3",
"swr": "^2.2.0"
Expand All @@ -39,6 +40,7 @@
"@types/node": "20.3.1",
"@types/react": "18.2.14",
"@types/react-dom": "18.2.6",
"@types/rss": "^0.0.30",
"autoprefixer": "^10.4.14",
"postcss": "^8.4.24",
"tailwindcss": "^3.3.2",
Expand Down
Loading

0 comments on commit 5bb0057

Please sign in to comment.