--- import BaseLayout from "../../layouts/BaseLayout.astro"; import { getCollection, type CollectionEntry } from "astro:content"; import { formatBlogDate, getTagHref } from "../../lib/blog"; import { getReadingTime } from "../../lib/readingTime"; type BlogPost = CollectionEntry<"blog">; export async function getStaticPaths() { const posts = await getCollection("blog", ({ data }) => !data.draft); return posts.map((post) => ({ params: { slug: post.slug }, props: { post, seriesPosts: post.data.series ? posts .filter( (candidate) => candidate.data.series?.name === post.data.series?.name, ) .sort((a, b) => { const partDifference = (a.data.series?.part ?? Number.MAX_SAFE_INTEGER) - (b.data.series?.part ?? Number.MAX_SAFE_INTEGER); if (partDifference !== 0) return partDifference; return ( a.data.pubDate.valueOf() - b.data.pubDate.valueOf() ); }) : [], relatedPosts: posts .filter((candidate) => candidate.slug !== post.slug) .map((candidate) => ({ post: candidate, score: (candidate.data.series?.name && candidate.data.series.name === post.data.series?.name ? 10 : 0) + candidate.data.tags.filter((tag) => post.data.tags.includes(tag), ).length, })) .sort((a, b) => { if (b.score !== a.score) return b.score - a.score; return ( b.post.data.pubDate.valueOf() - a.post.data.pubDate.valueOf() ); }) .filter((candidate) => candidate.score > 0) .slice(0, 2) .map((candidate) => candidate.post), }, })); } const { post, seriesPosts = [], relatedPosts = [], } = Astro.props as { post: BlogPost; seriesPosts: BlogPost[]; relatedPosts: BlogPost[]; }; const { Content } = await post.render(); const readingTime = getReadingTime(post.body); ---