--- import BaseLayout from './BaseLayout.astro'; import CommentSection from '../components/CommentSection.vue'; import LikeButton from '../components/LikeButton.vue'; import type { CollectionEntry } from 'astro:content'; interface Heading { depth: number; slug: string; text: string; } interface Props { post: CollectionEntry<'blog'>; headings?: Heading[]; } const { post, headings = [] } = Astro.props; const { title, description, pubDate, updatedDate, heroImage, heroAlt, tags, author, category } = post.data; // 格式化日期 const formatDate = (date: Date) => { return date.toLocaleDateString('zh-CN', { year: 'numeric', month: 'long', day: 'numeric', }); }; // 计算阅读时间(估算) const readingTime = Math.ceil(post.body?.split(/\s+/).length / 400) || 1; // 是否显示目录 const hasToc = headings.length > 0; // 过滤出 h2 和 h3 标题 const tocItems = headings.filter(h => h.depth >= 2 && h.depth <= 3); --- {hasToc && ( )} {hasToc && (
)} {hasToc && ( )}
{category && ( {category} )} {tags && tags.map((tag: string) => ( #{tag} ))}

{title}

{heroImage && (
{heroAlt
)}
{hasToc && ( )}