Skip to content

Commit 386514a

Browse files
committed
added astrojs rss feed for blog posts
1 parent 5a69475 commit 386514a

4 files changed

Lines changed: 111 additions & 0 deletions

File tree

package-lock.json

Lines changed: 87 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
@@ -13,6 +13,7 @@
1313
},
1414
"dependencies": {
1515
"@astrojs/mdx": "^5.0.3",
16+
"@astrojs/rss": "^4.0.18",
1617
"@tailwindcss/typography": "^0.5.19",
1718
"@tailwindcss/vite": "^4.2.4",
1819
"astro": "^6.1.8",

src/layouts/Base.astro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ const currentPath = Astro.url.pathname;
3939
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
4040
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
4141
<link rel="manifest" href="/site.webmanifest" />
42+
43+
<link rel="alternate" type="application/rss+xml" title="beparano.id" href="/rss.xml" />
4244
</head>
4345

4446
<body class="bg-paper text-ink flex flex-col min-h-screen">

src/pages/rss.xml.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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'))
7+
.filter(p => !p.data.draft)
8+
.sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf());
9+
10+
return rss({
11+
title: 'beparano.id',
12+
description: 'Thoughts on tech, books, food and more.',
13+
site: context.site!,
14+
items: posts.map(post => ({
15+
title: post.data.title,
16+
description: post.data.description,
17+
pubDate: post.data.date,
18+
link: `/blog/${post.id}/`,
19+
})),
20+
});
21+
}

0 commit comments

Comments
 (0)