--- import Breadcrumbs from '@/components/Breadcrumbs.astro' import PostNavigation from '@/components/PostNavigation.astro' import TableOfContents from '@/components/TableOfContents.astro' import { Button } from '@/components/ui/button' import { Separator } from '@/components/ui/separator' import Layout from '@/layouts/Layout.astro' import { parseAuthors } from '@/lib/server-utils' import { formatDate, readingTime } from '@/lib/utils' import { Icon } from 'astro-icon/components' import { Image } from 'astro:assets' import { type CollectionEntry, getCollection, render } from 'astro:content' export async function getStaticPaths() { const posts = (await getCollection('blog')) .filter((post) => !post.data.draft) .sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf()) return posts.map((post) => ({ params: { id: post.id }, props: post, })) } type Props = CollectionEntry<'blog'> const posts = (await getCollection('blog')) .filter((post) => !post.data.draft) .sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf()) function getPostIndex(id: string): number { return posts.findIndex((post) => post.id === id) } function getPrevPost(id: string): Props | null { const postIndex = getPostIndex(id) return postIndex !== -1 && postIndex < posts.length - 1 ? posts[postIndex + 1] : null } function getNextPost(id: string): Props | null { const postIndex = getPostIndex(id) return postIndex > 0 ? posts[postIndex - 1] : null } const currentPostId = Astro.params.id const nextPost = getNextPost(currentPostId) const prevPost = getPrevPost(currentPostId) const post = Astro.props const { Content, headings } = await render(post) const authors = await parseAuthors(post.data.authors ?? []) ---
{ post.data.image && ( {post.data.title} ) }

{post.data.title}

{formatDate(post.data.date)} {readingTime(post.body!)}
{headings.length > 0 && }