Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Rss feed solving #525 #635

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ next-env.d.ts

# contentlayer
.contentlayer
/.idea
36 changes: 36 additions & 0 deletions app/api/blog/feed.xml/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import Rss from "rss";
import { allBlogs } from "contentlayer/generated";

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

export async function GET(request: Request) {
try {
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'
}
})
} catch (error) {
console.error('Error generating RSS feed:', error);
return new Response('Error generating RSS feed', { status: 500 });
}
}
}
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