diff options
| author | Valentin Popov <valentin@popov.link> | 2026-04-22 21:53:50 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-04-22 21:53:50 +0300 |
| commit | 9a0746a4715400ab8ef37ec23a4df93ae712e74b (patch) | |
| tree | 5678821ab8e56f3098a26240f5db0f13fa25bf5c /src/pages/feed.xml.ts | |
| parent | a6efbdc3aba7cbc3918976ad1a3c4143363c6f7a (diff) | |
| download | popov.link-9a0746a4715400ab8ef37ec23a4df93ae712e74b.tar.xz popov.link-9a0746a4715400ab8ef37ec23a4df93ae712e74b.zip | |
feat: add RSS feed generation and update package metadata
- Implemented a new RSS feed generation feature in src/pages/feed.xml.ts, allowing users to follow blog updates.
- Updated package.json and package-lock.json to include license information and new type definitions for markdown-it and sanitize-html.
- Refactored createOgImage function to return Uint8Array instead of Buffer for better compatibility.
- Simplified pageSchema by removing the optional mainEntityId parameter for cleaner schema generation.
Diffstat (limited to 'src/pages/feed.xml.ts')
| -rw-r--r-- | src/pages/feed.xml.ts | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/pages/feed.xml.ts b/src/pages/feed.xml.ts new file mode 100644 index 0000000..9d0568f --- /dev/null +++ b/src/pages/feed.xml.ts @@ -0,0 +1,48 @@ +import type { APIContext } from "astro"; +import { getCollection } from "astro:content"; +import MarkdownIt from "markdown-it"; +import rss from "@astrojs/rss"; +import sanitizeHtml from "sanitize-html"; +import { config } from "../config"; + +const parser = new MarkdownIt({ html: false, linkify: true }); + +export async function GET(context: APIContext) { + const title = "RSS Feed | Valentin Popov Blog"; + const description = "Follow the latest posts from Valentin Popov via RSS."; + + const posts = (await getCollection("blog", ({ data }) => data.draft !== true)).sort((a, b) => b.data.datePublished.getTime() - a.data.datePublished.getTime()); + + const feedUrl = new URL("/feed.xml", context.site).toString(); + + return rss({ + title, + description, + site: context.site ?? config.author.url, + xmlns: { + atom: "http://www.w3.org/2005/Atom", + content: "http://purl.org/rss/1.0/modules/content/", + dc: "http://purl.org/dc/elements/1.1/", + }, + customData: `<atom:link href="${feedUrl}" rel="self" type="application/rss+xml"/>`, + items: posts.map((post) => ({ + title: post.data.title, + description: post.data.description, + link: `/blog/${post.id}/`, + pubDate: post.data.datePublished, + author: `${config.author.email} (${config.author.name})`, + content: sanitizeHtml(parser.render(post.body ?? ""), { + allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img", "pre", "code", "span"]), + allowedAttributes: { + ...sanitizeHtml.defaults.allowedAttributes, + img: ["src", "alt", "title", "loading", "decoding"], + code: ["class"], + span: ["class"], + pre: ["class"], + a: ["href", "name", "target", "rel"], + }, + }), + customData: `<dc:language>${post.data.lang}</dc:language>`, + })), + }); +} |
