diff --git a/src/pages/archives/[...slug].astro b/src/pages/archives/[...slug].astro index c024cf9..5cd0ac0 100644 --- a/src/pages/archives/[...slug].astro +++ b/src/pages/archives/[...slug].astro @@ -7,13 +7,23 @@ import { trackOf } from '../../content.config'; // URL = /archives/{slug},slug 即文件名,与 Halo 旧结构 1:1(不可改) export async function getStaticPaths() { - const posts = (await getCollection('posts', ({ data }) => !data.draft && !data.tags.includes('hidden'))).sort( + // 路径用全量(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(), ); - return posts.map((entry, i) => ({ - params: { slug: entry.id }, - props: { entry, prev: posts[i + 1] ?? null, next: posts[i - 1] ?? null }, - })); + 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 { diff --git a/src/pages/en/archives/[...slug].astro b/src/pages/en/archives/[...slug].astro index 05fa2e0..173c4c7 100644 --- a/src/pages/en/archives/[...slug].astro +++ b/src/pages/en/archives/[...slug].astro @@ -8,14 +8,24 @@ import AiTranslatedBadge from '../../../components/AiTranslatedBadge.astro'; import { t } from '../../../i18n/ui'; export async function getStaticPaths() { - const zh = (await getCollection('posts', ({ data }) => !data.draft && !data.tags.includes('hidden'))).sort( + // 路径全量(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 zh.map((entry, i) => ({ - params: { slug: entry.id }, - props: { entry, enEntry: en.get(entry.id) ?? null, prev: zh[i + 1] ?? null, next: zh[i - 1] ?? null }, - })); + 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 {