--- // /en/archives/{slug}:英文版文章页——postsEn 优先;缺译回退 zh 正文 + 醒目标注 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 AiTranslatedBadge from '../../../components/AiTranslatedBadge.astro'; import { t } from '../../../i18n/ui'; export async function getStaticPaths() { // 路径全量(hidden 样张出页);prev/next 滤 hidden(同 zh 轨修正) 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')); const en = new Map((await getCollection('postsEn')).map((e) => [e.id, e])); return all.map((entry) => { const i = nav.findIndex((e) => e.id === entry.id); return { params: { slug: entry.id }, props: { entry, enEntry: en.get(entry.id) ?? null, prev: i >= 0 ? (nav[i + 1] ?? null) : null, next: i > 0 ? (nav[i - 1] ?? null) : null, }, }; }); } interface Props { entry: CollectionEntry<'posts'>; enEntry: CollectionEntry<'postsEn'> | null; prev: CollectionEntry<'posts'> | null; next: CollectionEntry<'posts'> | null; } const { entry, enEntry, prev, next } = Astro.props; // 译文存在则渲染译文;否则回退 zh 正文(语言切换的降级承诺:单篇未译不破站) const { Content } = await render(enEntry ?? entry); const isReading = entry.data.category === 'reading'; const date = entry.data.pubDate.toISOString().slice(0, 10); const words = (enEntry?.body ?? entry.body ?? '').split(/\s+/).length; const minutes = Math.max(1, Math.ceil(words / 220)); ---

{isReading ? t('category_reading', 'en') : entry.data.category === 'tech' ? t('category_tech', 'en') : t('category_photo', 'en')}

{enEntry?.data.title ?? entry.data.title}