--- import ArticleSidebar from '@/components/ArticleSidebar.astro'; import PostCopyrightCard from '@/components/PostCopyrightCard.astro'; import BaseLayout from '@/layouts/BaseLayout.astro'; import { getAllPosts } from '@/lib/posts'; export function getStaticPaths() { return getAllPosts().map((post) => ({ params: { slug: post.slug }, props: { post }, })); } const { post } = Astro.props; const { Content } = post; const allPosts = getAllPosts(); const rawContent = post.rawContent?.() ?? ''; const textContent = rawContent .replace(/```[\s\S]*?```/g, '') .replace(/<[^>]+>/g, '') .replace(/[#>*_`~\-\[\]\(\)!]/g, '') .replace(/\s+/g, ''); const wordCount = textContent.length; const wordCountText = wordCount >= 1000 ? `${(wordCount / 1000).toFixed(1)}k` : String(wordCount); const readingMinutes = Math.max(1, Math.ceil(wordCount / 400)); function slugifyHeading(value: string): string { return value .trim() .toLowerCase() .replace(/<[^>]+>/g, '') .replace(/[`*_~[\]()]/g, '') .replace(/[^\p{Letter}\p{Number}\s-]/gu, '') .replace(/\s+/g, '-') .replace(/-+/g, '-') .replace(/^-|-$/g, ''); } function makeToc(raw: string) { const used = new Map(); let inFence = false; return raw .split(/\r?\n/) .flatMap((line) => { if (/^\s*```/.test(line)) { inFence = !inFence; return []; } if (inFence) return []; const match = /^(#{1,3})\s+(.+?)\s*#*$/.exec(line); if (!match) return []; const text = match[2].replace(/<[^>]+>/g, '').trim(); if (!text) return []; const baseId = slugifyHeading(text) || 'section'; const count = used.get(baseId) ?? 0; used.set(baseId, count + 1); return [{ depth: match[1].length, text, id: count === 0 ? baseId : `${baseId}-${count}`, }]; }); } const toc = makeToc(post.rawContent?.() ?? ''); const relatedPosts = allPosts .filter((item) => item.slug !== post.slug) .filter((item) => item.categories.some((category) => post.categories.includes(category))) .slice(0, 8); ---
{post.cover && }

{post.title}

{post.cover ? (
发布于 {post.dateText} {post.categories[0] && {post.categories[0]}} 总字数:{wordCountText} 阅读时长:{readingMinutes} 分钟
) : (
{post.categories.map((category) => {category})} {post.tags.map((tag) => #{tag})}
)}
{post.summary && (

{post.summary}

清羽のAI摘要 KIMI-K2.5
)}