Skip to content

Commit 50734c8

Browse files
Copilotgarrytrinder
andcommitted
Add RSS feed for blog posts
Co-authored-by: garrytrinder <11563347+garrytrinder@users.noreply.github.com>
1 parent 5c3bb59 commit 50734c8

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

package-lock.json

Lines changed: 54 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
@@ -10,6 +10,7 @@
1010
"astro": "astro"
1111
},
1212
"dependencies": {
13+
"@astrojs/rss": "^4.0.15",
1314
"@tailwindcss/vite": "^4.1.18",
1415
"astro": "^5.17.2",
1516
"tailwindcss": "^4.1.18"

src/layouts/Layout.astro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const ogImage = image ? new URL(image, Astro.site ?? 'https://devproxy.net').hre
2121
<meta name="description" content={description} />
2222
<meta name="generator" content={Astro.generator} />
2323
<title>{title} | Dev Proxy</title>
24+
<link rel="alternate" type="application/rss+xml" title="Dev Proxy Blog" href={`${import.meta.env.BASE_URL}rss.xml`} />
2425

2526
<!-- Open Graph -->
2627
<meta property="og:type" content="website" />

src/pages/rss.xml.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import rss from '@astrojs/rss';
2+
import { getCollection } from 'astro:content';
3+
import type { APIContext } from 'astro';
4+
5+
export async function GET(context: APIContext) {
6+
const posts = (await getCollection('blog')).sort(
7+
(a, b) => b.data.date.valueOf() - a.data.date.valueOf()
8+
);
9+
10+
return rss({
11+
title: 'Dev Proxy Blog',
12+
description: 'Release announcements, how-to guides, and insights from the Dev Proxy team.',
13+
site: context.site?.href ?? 'https://devproxy.net',
14+
items: posts.map((post) => ({
15+
title: post.data.title,
16+
description: post.data.description,
17+
pubDate: post.data.date,
18+
author: post.data.author,
19+
link: `${import.meta.env.BASE_URL}blog/${post.id.replace(/\.md$/, '')}/`,
20+
})),
21+
});
22+
}

0 commit comments

Comments
 (0)