From d32269abe340d72ed0102f7b93077ad29d5daef8 Mon Sep 17 00:00:00 2001 From: Anton Vakhrushev Date: Sat, 7 Mar 2026 11:19:25 +0300 Subject: [PATCH] Add robots and rss --- public/robots.txt | 2 ++ src/pages/rss.xml.ts | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 public/robots.txt create mode 100644 src/pages/rss.xml.ts diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000..5961450 --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Sitemap: https://vakhrushev.me/sitemap-index.xml diff --git a/src/pages/rss.xml.ts b/src/pages/rss.xml.ts new file mode 100644 index 0000000..3927cf8 --- /dev/null +++ b/src/pages/rss.xml.ts @@ -0,0 +1,24 @@ +import rss from '@astrojs/rss'; +import { getCollection } from 'astro:content'; +import { parseDateFromId } from '../utils/articles'; +import type { APIContext } from 'astro'; + +export async function GET(context: APIContext) { + const articles = await getCollection('articles', ({ data }) => !data.draft); + + const sorted = articles.sort( + (a, b) => parseDateFromId(b.id).getTime() - parseDateFromId(a.id).getTime(), + ); + + return rss({ + title: 'Антон Вахрушев', + description: 'Блог о программировании', + site: context.site!.toString(), + items: sorted.map((article) => ({ + title: article.data.title, + description: article.data.description, + pubDate: parseDateFromId(article.id), + link: `/articles/${article.id}/`, + })), + }); +}