Indieweb draft, creates per-tag RSS feeds.
This commit is contained in:
22
src/lib/blog.ts
Normal file
22
src/lib/blog.ts
Normal 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 || []);
|
||||
}
|
||||
Reference in New Issue
Block a user