From e431533a397fb2899df8f1f78a1d455f3bff9fe4 Mon Sep 17 00:00:00 2001 From: lew Date: Thu, 26 Mar 2026 21:31:17 +0000 Subject: [PATCH] feat: short excerpt in rss feed --- www/src/pages/feed.xml.ts | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/www/src/pages/feed.xml.ts b/www/src/pages/feed.xml.ts index 98b2e95..e01b520 100644 --- a/www/src/pages/feed.xml.ts +++ b/www/src/pages/feed.xml.ts @@ -4,10 +4,21 @@ import type { APIContext } from 'astro'; import { getSlug, enrichPostsWithDates } from '../lib/md'; import { getTxtFiles } from '../lib/txt'; +function excerpt(markdown: string | undefined, maxLen = 160): string { + if (!markdown) return ''; + return markdown + .replace(/^#+\s+.*$/gm, '') + .replace(/!?\[([^\]]*)\]\([^)]*\)/g, '$1') + .replace(/[*_~`]/g, '') + .replace(/:[a-z]+\[([^\]]*)\]/g, '$1') + .replace(/\n+/g, ' ') + .trim() + .slice(0, maxLen); +} + export async function GET(context: APIContext) { const rawPosts = await getCollection('md'); const posts = enrichPostsWithDates(rawPosts); - const bookmarks = await getCollection('bookmarks'); const txtFiles = getTxtFiles(); const items = [ @@ -15,25 +26,19 @@ export async function GET(context: APIContext) { title: post.data.title, pubDate: post.dates.created, link: `/${getSlug(post.id)}`, - description: post.data.title, + description: excerpt((post as any).body) || post.data.title, })), ...txtFiles.map(txt => ({ title: txt.name, pubDate: txt.date, link: `/${txt.name}`, - description: txt.name, - })), - ...bookmarks.map(b => ({ - title: b.data.title, - pubDate: b.data.date, - link: b.data.url, - description: b.data.title, + description: txt.description || txt.name, })), ].sort((a, b) => b.pubDate.getTime() - a.pubDate.getTime()); return rss({ title: 'wynne.rs', - description: '', + description: 'personal website of lewis m.w.', site: context.site ?? 'https://wynne.rs', items, });