feat: create separated rss feeds
All checks were successful
Docker / build-and-push-image (push) Successful in 2m11s

This commit is contained in:
Troy 2025-05-06 22:50:48 +01:00
parent 4f9ebdcc66
commit 782bfc7c90
Signed by: troy
GPG key ID: DFC06C02ED3B4711
10 changed files with 86 additions and 6 deletions

23
src/pages/posts.xml.ts Normal file
View file

@ -0,0 +1,23 @@
import rss from "@astrojs/rss";
import { SITE } from "@consts";
import { getCollection } from "astro:content";
export async function GET(context: { site: string }) {
const posts = (await getCollection("posts"))
.filter((post) => !post.data.draft)
.sort(
(a, b) =>
new Date(b.data.date).valueOf() - new Date(a.data.date).valueOf(),
);
return rss({
title: `${SITE.TITLE} Posts`,
description: SITE.DESCRIPTION,
site: context.site,
items: posts.map((item) => ({
title: item.data.title,
description: item.data.description,
pubDate: item.data.date,
link: `/${item.collection}/${item.slug}/`,
})),
});
}

View file

@ -3,6 +3,7 @@ import { getCollection } from "astro:content";
import { SITE, POSTS } from "@consts";
import ShowcasePost from "@components/ShowcasePost.astro";
import Layout from "@layouts/Layout.astro";
import Link from "@components/Link.astro";
const posts = (await getCollection("posts"))
.filter((post) => !post.data.draft)
@ -22,4 +23,11 @@ const posts = (await getCollection("posts"))
posts.map((article: any) => <ShowcasePost collection={article} />)
}
</ol>
<div class="flex justify-end">
<Link
href="/posts.xml"
class="text-tertiary hover:text-secondary text-xs transition-colors duration-300"
>View posts feed</Link
>
</div>
</Layout>

23
src/pages/projects.xml.ts Normal file
View file

@ -0,0 +1,23 @@
import rss from "@astrojs/rss";
import { SITE } from "@consts";
import { getCollection } from "astro:content";
export async function GET(context: { site: string }) {
const projects = (await getCollection("projects"))
.filter((project) => !project.data.draft)
.sort(
(a, b) =>
new Date(b.data.date).valueOf() - new Date(a.data.date).valueOf(),
);
return rss({
title: `${SITE.TITLE} Projects`,
description: SITE.DESCRIPTION,
site: context.site,
items: projects.map((item) => ({
title: item.data.title,
description: item.data.description,
pubDate: item.data.date,
link: `/${item.collection}/${item.slug}/`,
})),
});
}

View file

@ -3,6 +3,7 @@ import { getCollection } from "astro:content";
import { PROJECTS, SITE } from "@consts";
import Layout from "@layouts/Layout.astro";
import ShowcaseProject from "@components/ShowcaseProject.astro";
import Link from "@components/Link.astro";
const projects = (await getCollection("projects"))
.filter((project) => !project.data.draft)
@ -18,4 +19,11 @@ const projects = (await getCollection("projects"))
>
{projects.map((article: any) => <ShowcaseProject collection={article} />)}
</ol>
<div class="flex justify-end">
<Link
href="/projects.xml"
class="text-tertiary hover:text-secondary text-xs transition-colors duration-300"
>View projects feed</Link
>
</div>
</Layout>