fix(media): 详情页路径全量+prev/next 滤 hidden(op-artalk 车道指正)

- getStaticPaths 恢复只滤 draft:hidden 样张需出静态页(可访问不列出)
- prev/next 从 hidden 过滤后的导航数组取位:真实文章上下篇不链样张

验证: build 23 页;media-sample zh/en 双页产物在;/media/ 绝对引用 ✓;
      首页与 RSS 零 media-sample 泄漏

Spec: 2026-10-25_add-media-and-polish

Co-authored-by: GLM-5.3
This commit is contained in:
wait4xandGLM-5.3 committed 2026-10-25 11:53:22 +08:00
1 parent 71a799bd97
commit a4388df35e
2 files changed
+28 -8

No files matched your search

+14 -4
View File
@@ -7,13 +7,23 @@ import { trackOf } from '../../content.config';
// URL = /archives/{slug},slug 即文件名,与 Halo 旧结构 1:1(不可改) // URL = /archives/{slug},slug 即文件名,与 Halo 旧结构 1:1(不可改)
export async function getStaticPaths() { 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(), (a, b) => b.data.pubDate.getTime() - a.data.pubDate.getTime(),
); );
return posts.map((entry, i) => ({ 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 }, params: { slug: entry.id },
props: { entry, prev: posts[i + 1] ?? null, next: posts[i - 1] ?? null }, props: {
})); entry,
prev: i >= 0 ? (nav[i + 1] ?? null) : null,
next: i > 0 ? (nav[i - 1] ?? null) : null,
},
};
});
} }
interface Props { interface Props {
+14 -4
View File
@@ -8,14 +8,24 @@ import AiTranslatedBadge from '../../../components/AiTranslatedBadge.astro';
import { t } from '../../../i18n/ui'; import { t } from '../../../i18n/ui';
export async function getStaticPaths() { 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(), (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])); const en = new Map((await getCollection('postsEn')).map((e) => [e.id, e]));
return zh.map((entry, i) => ({ return all.map((entry) => {
const i = nav.findIndex((e) => e.id === entry.id);
return {
params: { slug: entry.id }, params: { slug: entry.id },
props: { entry, enEntry: en.get(entry.id) ?? null, prev: zh[i + 1] ?? null, next: zh[i - 1] ?? null }, 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 { interface Props {