Skip to content

Commit bdbf347

Browse files
committed
feat: include full post content in RSS feed
Full text in an RSS feed is more convenient for users, see this article[1] for more information. Summary of the motivation: - Easier for users because they don't have to visit the blog - Text within the article can be searched with the reader - Offline reading will be possible [1]: https://openrss.org/blog/full-text-in-rss-please
1 parent dba6ead commit bdbf347

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

bun.lock

Lines changed: 44 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
"@tailwindcss/forms": "^0.5.10",
1919
"@tailwindcss/typography": "^0.5.16",
2020
"@types/bun": "latest",
21+
"@types/markdown-it": "^14.1.2",
22+
"@types/sanitize-html": "^2.16.0",
2123
"fast-xml-parser": "^4.5.3",
2224
"kleur": "^4.1.5",
2325
"prettier": "^3.5.3",
@@ -30,6 +32,8 @@
3032
"@astrojs/tailwind": "^5.1.5",
3133
"@astrojs/ts-plugin": "^1.10.4",
3234
"astro": "^4.16.18",
35+
"markdown-it": "^14.1.0",
36+
"sanitize-html": "^2.17.0",
3337
"tailwindcss": "^3.4.17"
3438
}
3539
}

src/pages/posts.rss.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import rss from "@astrojs/rss";
22
import { getCollection } from "astro:content";
33
import type { APIContext } from "astro";
4+
import sanitizeHtml from 'sanitize-html';
5+
import MarkdownIt from 'markdown-it';
6+
7+
const parser = new MarkdownIt();
48

59
export async function GET(context: APIContext) {
610
const posts = await getCollection("posts");
@@ -13,6 +17,9 @@ export async function GET(context: APIContext) {
1317
.map((post) => ({
1418
title: post.data.title,
1519
description: post.data.description,
20+
content: sanitizeHtml(parser.render(post.body), {
21+
allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img'])
22+
}),
1623
author: post.data.author,
1724
pubDate: post.data.date,
1825
categories: [post.data.type],

0 commit comments

Comments
 (0)