Skip to content

Commit 2426e90

Browse files
authored
Merge pull request #32 from ansidev/feature/rss
Feature: RSS
2 parents 63c3d23 + 8dab828 commit 2426e90

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
},
1717
"dependencies": {
1818
"@astrojs/partytown": "^1.0.3",
19+
"@astrojs/rss": "^2.1.1",
1920
"@astrojs/sitemap": "^1.1.0",
2021
"@astrojs/tailwind": "^3.0.1",
2122
"astro": "^2.0.15",

pnpm-lock.yaml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/pages/rss.xml.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import rss from '@astrojs/rss'
2+
import type { APIContext } from 'astro'
3+
import { getCollection } from 'astro:content'
4+
5+
import siteConfig from '@/configs/site'
6+
7+
const { title, description } = siteConfig
8+
9+
export const get = async ({ site }: APIContext) => {
10+
if (site === undefined || site.toString().length === 0) {
11+
return {
12+
body: ''
13+
}
14+
}
15+
16+
const allPosts = await getCollection('leetcode-solutions')
17+
18+
return rss({
19+
title,
20+
description,
21+
site: site.toString(),
22+
items: allPosts.map((post) => ({
23+
title: post.data.title,
24+
description: `LeetCode Problem #${post.data.title}`,
25+
pubDate: new Date(post.data.pubDate),
26+
link: `/${post.slug}`,
27+
})),
28+
customData: '<language>en-US</language>',
29+
})
30+
}

0 commit comments

Comments
 (0)