Skip to content

Commit 752f28f

Browse files
authored
docs(blog): export blog as feed (#6958)
1 parent d7c2579 commit 752f28f

File tree

1 file changed

+46
-0
lines changed
  • packages/web/docs/src/app/blog/feed.xml

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// eslint-disable-next-line import/no-extraneous-dependencies
2+
import RSS from 'rss';
3+
import { getPageMap } from '@theguild/components/server';
4+
import { isBlogPost } from '../blog-types';
5+
6+
export async function GET() {
7+
const [_meta, _indexPage, ...pageMap] = await getPageMap('/blog');
8+
const allPosts = pageMap
9+
.filter(isBlogPost)
10+
.map(
11+
item =>
12+
({
13+
title: item.frontMatter.title,
14+
date: new Date(item.frontMatter.date),
15+
url: `https://the-guild.dev/graphql/hive${item.route}`,
16+
description: (item.frontMatter as any).description ?? '',
17+
author:
18+
typeof item.frontMatter.authors === 'string'
19+
? item.frontMatter.authors
20+
: item.frontMatter.authors.at(0),
21+
categories: Array.isArray(item.frontMatter.tags)
22+
? item.frontMatter.tags
23+
: [item.frontMatter.tags],
24+
}) satisfies RSS.ItemOptions,
25+
)
26+
.sort((a, b) => b.date.getTime() - a.date.getTime());
27+
28+
const feed = new RSS({
29+
title: 'Hive Blog',
30+
site_url: 'https://the-guild.dev/graphql/hive/blog',
31+
feed_url: 'https://the-guild.dev/graphql/hive/blog/feed.xml',
32+
});
33+
34+
for (const item of allPosts) {
35+
feed.item(item);
36+
}
37+
38+
return new Response(feed.xml({ indent: true }), {
39+
headers: {
40+
'Content-Type': 'application/xml; charset=utf-8',
41+
},
42+
});
43+
}
44+
45+
export const dynamic = 'force-static';
46+
export const config = { runtime: 'edge' };

0 commit comments

Comments
 (0)