--- import { type CollectionEntry, getCollection, getEntry } from 'astro:content' import Layout from '@layouts/Layout.astro' import Container from '@components/Container.astro' import { formatDate, readingTime } from '@lib/utils' import PostNavigation from '@components/PostNavigation.astro' import TableOfContents from '@components/TableOfContents.astro' import { Image } from 'astro:assets' import { Badge, badgeVariants } from '@/components/ui/badge' import { Button } from '@/components/ui/button' import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, } from '@/components/ui/breadcrumb' import { HomeIcon } from 'lucide-react' import { cn } from '@/lib/utils' import { Separator } from '@/components/ui/separator' import Link from '@components/Link.astro' 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: { slug: post.slug }, 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(slug: string): number { return posts.findIndex((post) => post.slug === slug) } function getNextPost(slug: string): Props | null { const postIndex = getPostIndex(slug) return postIndex !== -1 && postIndex < posts.length - 1 ? posts[postIndex + 1] : null } function getPrevPost(slug: string): Props | null { const postIndex = getPostIndex(slug) return postIndex > 0 ? posts[postIndex - 1] : null } const currentPostSlug = Astro.params.slug const nextPost = getNextPost(currentPostSlug) const prevPost = getPrevPost(currentPostSlug) const post = Astro.props const { Content, headings } = await post.render() let author = null if ( post.data.author && typeof post.data.author === 'object' && 'collection' in post.data.author ) { author = await getEntry(post.data.author) } else if (typeof post.data.author === 'string') { author = { data: { name: post.data.author, avatar: '/favicons/android-chrome-512x512.png', }, } } --- Blog {post.data.title} { post.data.image && ( {post.data.title} ) }

{post.data.title}

{ author && ( <>
{author.data.name} {typeof post.data.author === 'object' && 'collection' in post.data.author ? ( {author.data.name} ) : ( {author.data.name} )}
) } {formatDate(post.data.date)} {readingTime(post.body)}
{ post.data.tags && post.data.tags.length > 0 ? ( post.data.tags.map((tag) => ( {tag} )) ) : ( No tags available ) }
{headings.length > 0 && }