mercury/src/pages/post/[...slug].astro
2025-05-13 22:05:28 +08:00

36 lines
No EOL
1,022 B
Text

---
import Layout from '../../layouts/Layout.astro';
import { getCollection } from 'astro:content';
import Comments from "../../components/Comments.astro";
export async function getStaticPaths() {
const blogEntries = await getCollection('posts');
return blogEntries.map(entry => ({
params: { slug: entry.slug }, props: { entry },
}));
}
const { entry } = Astro.props;
const { Content } = await entry.render();
const slug = Astro.params.slug;
---
<Layout
title={entry.data.title}
path={`~/grassblock/micr0blog/blog/${slug}`}
description={entry.data.description}
>
<h1 class="post-title">{entry.data.title}</h1>
<span class="post-date">{new Date(entry.data.pubDate).toISOString().split('T')[0]}</span>
<div class="post-content">
<Content />
</div>
<div style="margin-top: 2rem; border-top: 1px solid var(--border-color); padding-top: 1rem;">
<h2>Comments</h2>
<Comments path={`post/${slug}`} />
<a href="/blog">&larr; Back to posts</a>
</div>
</Layout>