Indieweb draft, creates per-tag RSS feeds.

This commit is contained in:
2026-03-16 11:27:45 -07:00
parent eb067b6a39
commit 8f6de2cced
5 changed files with 88 additions and 39 deletions

22
src/lib/blog.ts Normal file
View File

@@ -0,0 +1,22 @@
import { type CollectionEntry, getCollection } from "astro:content";
function publishedOnly(
p: CollectionEntry<"blog">,
): p is CollectionEntry<"blog"> & { data: { pubDate: Date } } {
return p.data.pubDate !== undefined;
}
export async function getPublishedPosts(
tag?: string,
): Promise<CollectionEntry<"blog">[]> {
const allPosts = (await getCollection("blog", publishedOnly)).sort(
(a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf(),
);
return tag ? allPosts.filter((p) => p.data.tags.includes(tag)) : allPosts;
}
export async function getAllTags(): Promise<string[]> {
const posts = await getCollection("blog", publishedOnly);
return posts.flatMap((p) => p.data.tags || []);
}