Skip to content

Commit 4678492

Browse files
committed
fix zh-Hans about page not found by rewriting using getCollectionInLocaleWithFallbacks
1 parent 3040e06 commit 4678492

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

src/pages/[locale]/about.astro

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
---
2-
import { getEntry } from "astro:content";
2+
import { getCollectionInLocaleWithFallbacks } from "@pages/_utils";
33
import AboutLayout from "@layouts/AboutLayout.astro";
4-
import { defaultLocale } from "../../i18n/const";
4+
import { nonDefaultSupportedLocales, defaultLocale } from "@i18n/const";
55
import { setJumpToState } from "../../globals/state";
6-
import { nonDefaultSupportedLocales } from "@/src/i18n/const";
6+
import type { CollectionEntry } from "astro:content";
77
8-
export const getStaticPaths = async () => {
9-
const defaultAboutEntry = await getEntry(
10-
"text-detail",
11-
`${defaultLocale}/about`
12-
)!;
13-
const pages = await Promise.all(
14-
nonDefaultSupportedLocales.map(async (locale) => {
15-
const aboutEntry = await getEntry("text-detail", `${locale}/about`);
16-
return {
17-
params: { locale },
18-
props: {
19-
entry: aboutEntry ?? defaultAboutEntry,
20-
},
21-
};
22-
})
23-
);
24-
return pages;
25-
};
8+
export async function getStaticPaths() {
9+
const pages = nonDefaultSupportedLocales.map(async (locale) => {
10+
const entries = await getCollectionInLocaleWithFallbacks(
11+
"text-detail",
12+
locale
13+
);
14+
const aboutEntry = entries.find(entry =>
15+
entry.id.endsWith('/about.mdx') ||
16+
entry.id === `${defaultLocale}/about.mdx`
17+
) as CollectionEntry<"text-detail">;
18+
19+
return {
20+
params: { locale },
21+
props: { entry: aboutEntry },
22+
};
23+
});
24+
25+
return await Promise.all(pages);
26+
}
2627
2728
const { entry } = Astro.props;
2829
setJumpToState(null);

0 commit comments

Comments
 (0)