Add robots and rss
This commit is contained in:
24
src/pages/rss.xml.ts
Normal file
24
src/pages/rss.xml.ts
Normal file
@@ -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}/`,
|
||||
})),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user