--- import type { CollectionEntry } from 'astro:content'; import { getCollection, render } from 'astro:content'; import BaseLayout from '../../layouts/BaseLayout.astro'; import ArtalkComments from '../../components/ArtalkComments.astro'; import { trackOf } from '../../content.config'; // URL = /archives/{slug},slug 即文件名,与 Halo 旧结构 1:1(不可改) export async function getStaticPaths() { // 路径用全量(hidden 样张也要出静态页);prev/next 导航滤 hidden // (真实文章的上下篇不链向样张——op-artalk 车道连带提醒的实现) const all = (await getCollection('posts', ({ data }) => !data.draft)).sort( (a, b) => b.data.pubDate.getTime() - a.data.pubDate.getTime(), ); const nav = all.filter(({ data }) => !data.tags.includes('hidden')); return all.map((entry) => { const i = nav.findIndex((e) => e.id === entry.id); return { params: { slug: entry.id }, props: { entry, prev: i >= 0 ? (nav[i + 1] ?? null) : null, next: i > 0 ? (nav[i - 1] ?? null) : null, }, }; }); } interface Props { entry: CollectionEntry<'posts'>; prev: CollectionEntry<'posts'> | null; next: CollectionEntry<'posts'> | null; } const { entry, prev, next } = Astro.props; const { Content, headings } = await render(entry); const isReading = entry.data.category === 'reading'; const date = entry.data.pubDate.toISOString().slice(0, 10); // 阅读时长:正文汉字数 / 400 向上取整(最低 1 分钟) const hanzi = entry.body?.match(/[\u4e00-\u9fff]/g)?.length ?? 0; const minutes = Math.max(1, Math.ceil(hanzi / 400)); const toc = headings.filter((h) => h.depth === 2 || h.depth === 3); --- {isReading ? (

Reading · {trackOf(entry.data.category)}

{entry.data.title}