Skip to content

Commit 3cb8595

Browse files
authored
Merge pull request #86 from hydro-dev/translate
docs: en translation
2 parents 7bc84bc + 41bf757 commit 3cb8595

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+4363
-179
lines changed

app/(home)/layout.tsx

Lines changed: 0 additions & 7 deletions
This file was deleted.

app/[lang]/(home)/layout.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { ReactNode } from 'react';
2+
import { HomeLayout } from 'fumadocs-ui/layouts/home';
3+
import { baseOptions } from '@/lib/layout.shared';
4+
5+
export default async function Layout({
6+
params,
7+
children,
8+
}: {
9+
params: Promise<{ lang: string }>;
10+
children: ReactNode;
11+
}) {
12+
const { lang } = await params;
13+
return <HomeLayout {...baseOptions(lang)}>{children}</HomeLayout>;
14+
}
Lines changed: 161 additions & 56 deletions
Large diffs are not rendered by default.
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { DocsLayout } from 'fumadocs-ui/layouts/docs';
22
import type { ReactNode } from 'react';
3-
import { baseOptions } from '@/app/layout.config';
3+
import { baseOptions } from '@/lib/layout.shared';
44
import { source } from '@/lib/source';
55
import { GithubInfo } from 'fumadocs-ui/components/github-info';
66
import { RootToggle } from '@/components/RootToggle';
@@ -10,12 +10,18 @@ const maps = {
1010
'Tools': <GithubInfo owner="hydro-dev" repo="xcpc-tools" />,
1111
};
1212

13-
export default async function Layout({ children, params }: { children: ReactNode, params: Promise<{ slug?: string[] }> }) {
14-
const { slug } = await params;
13+
export default async function Layout({
14+
children,
15+
params,
16+
}: {
17+
children: ReactNode;
18+
params: Promise<{ lang: string; slug?: string[] }>;
19+
}) {
20+
const { lang, slug } = await params;
1521
return (
1622
<DocsLayout
17-
tree={source.pageTree}
18-
{...baseOptions}
23+
tree={source.getPageTree(lang)}
24+
{...baseOptions(lang)}
1925
links={Object.keys(maps).find((key) => slug?.[0] === key) ? [
2026
{
2127
type: 'custom',
@@ -30,12 +36,12 @@ export default async function Layout({ children, params }: { children: ReactNode
3036
{
3137
title: 'Hydro',
3238
description: 'The Online Judge System',
33-
url: '/docs/Hydro',
39+
url: `/${lang}/docs/Hydro`,
3440
},
3541
{
3642
title: 'XCPC-Tools',
3743
description: 'Tools for on-site contests',
38-
url: '/docs/Tools',
44+
url: `/${lang}/docs/Tools`,
3945
},
4046
]}
4147
/>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { source } from '@/lib/source';
2+
import { Popup, PopupContent, PopupTrigger } from 'fumadocs-twoslash/ui';
3+
import { Callout } from 'fumadocs-ui/components/callout';
4+
import {
5+
DocsPage,
6+
DocsBody,
7+
DocsDescription,
8+
DocsTitle,
9+
} from 'fumadocs-ui/page';
10+
import { notFound } from 'next/navigation';
11+
import defaultMdxComponents from 'fumadocs-ui/mdx';
12+
13+
export default async function Page(props: {
14+
params: Promise<{ lang: string; slug?: string[] }>;
15+
}) {
16+
const params = await props.params;
17+
const page = source.getPage(params.slug, params.lang);
18+
if (!page) notFound();
19+
20+
const MDX = page.data.body;
21+
22+
return (
23+
<DocsPage toc={page.data.toc} full={page.data.full}>
24+
<DocsTitle>{page.data.title}</DocsTitle>
25+
<DocsDescription>{page.data.description}</DocsDescription>
26+
<DocsBody>
27+
<MDX components={{
28+
...defaultMdxComponents,
29+
Popup,
30+
PopupContent,
31+
PopupTrigger,
32+
Callout,
33+
}} />
34+
</DocsBody>
35+
</DocsPage>
36+
);
37+
}
38+
39+
export async function generateStaticParams() {
40+
return source.generateParams();
41+
}
42+
43+
export async function generateMetadata(props: {
44+
params: Promise<{ lang: string; slug?: string[] }>;
45+
}) {
46+
const params = await props.params;
47+
const page = source.getPage(params.slug, params.lang);
48+
if (!page) notFound();
49+
50+
return {
51+
title: page.data.title,
52+
description: page.data.description,
53+
};
54+
}

app/[lang]/layout.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { RootProvider } from 'fumadocs-ui/provider/next';
2+
import type { ReactNode } from 'react';
3+
import { i18nUI } from '@/lib/layout.shared';
4+
import { i18n } from '@/lib/i18n';
5+
6+
export default async function LangLayout({
7+
params,
8+
children,
9+
}: {
10+
params: Promise<{ lang: string }>;
11+
children: ReactNode;
12+
}) {
13+
const { lang } = await params;
14+
15+
return (
16+
<RootProvider
17+
i18n={i18nUI.provider(lang)}
18+
search={{
19+
options: {
20+
type: 'static',
21+
},
22+
}}
23+
>
24+
{children}
25+
</RootProvider>
26+
);
27+
}
28+
29+
export function generateStaticParams() {
30+
return i18n.languages.map((lang) => ({ lang }));
31+
}

app/api/search/route.ts

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,25 @@ import { stopwords as mandarinStopwords } from "@orama/stopwords/mandarin";
55

66
export const revalidate = false;
77

8-
const tokenizer = createTokenizer({
8+
const mandarinTokenizer = createTokenizer({
99
language: 'mandarin',
1010
stopWords: mandarinStopwords,
1111
});
1212

13-
const search = {
14-
tokenizer,
15-
components: {
16-
tokenizer,
17-
},
18-
search: {
19-
threshold: 1.5,
20-
tolerance: 2,
21-
boost: {
22-
title: 2,
23-
content: 1,
13+
export const { staticGET: GET } = createFromSource(source, {
14+
localeMap: {
15+
zh: {
16+
tokenizer: mandarinTokenizer,
17+
components: {
18+
tokenizer: mandarinTokenizer,
19+
},
20+
search: {
21+
threshold: 1.5,
22+
tolerance: 2,
23+
},
24+
},
25+
en: {
26+
language: 'english',
2427
},
2528
},
26-
insertOptions: {
27-
batchSize: 100,
28-
async: true,
29-
},
30-
};
31-
32-
export const { staticGET: GET } = createFromSource(source, search);
29+
});

app/docs/[[...slug]]/page.tsx

Lines changed: 8 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,16 @@
1+
import { redirect } from 'next/navigation';
12
import { source } from '@/lib/source';
2-
import { Popup, PopupContent, PopupTrigger } from 'fumadocs-twoslash/ui';
3-
import { Callout } from 'fumadocs-ui/components/callout';
4-
import {
5-
DocsPage,
6-
DocsBody,
7-
DocsDescription,
8-
DocsTitle,
9-
} from 'fumadocs-ui/page';
10-
import { notFound } from 'next/navigation';
11-
import defaultMdxComponents from 'fumadocs-ui/mdx';
123

13-
export default async function Page(props: {
4+
export default async function DocsRedirectPage(props: {
145
params: Promise<{ slug?: string[] }>;
156
}) {
16-
const params = await props.params;
17-
const page = source.getPage(params.slug);
18-
if (!page) notFound();
19-
20-
const MDX = page.data.body;
21-
22-
return (
23-
<DocsPage toc={page.data.toc} full={page.data.full}>
24-
<DocsTitle>{page.data.title}</DocsTitle>
25-
<DocsDescription>{page.data.description}</DocsDescription>
26-
<DocsBody>
27-
<MDX components={{
28-
...defaultMdxComponents,
29-
Popup,
30-
PopupContent,
31-
PopupTrigger,
32-
Callout,
33-
}} />
34-
</DocsBody>
35-
</DocsPage>
36-
);
7+
const { slug } = await props.params;
8+
const path = slug?.length ? `/zh/docs/${slug.join('/')}` : '/zh/docs';
9+
redirect(path);
3710
}
3811

3912
export async function generateStaticParams() {
40-
return source.generateParams();
41-
}
42-
43-
export async function generateMetadata(props: {
44-
params: Promise<{ slug?: string[] }>;
45-
}) {
46-
const params = await props.params;
47-
const page = source.getPage(params.slug);
48-
if (!page) notFound();
49-
50-
return {
51-
title: page.data.title,
52-
description: page.data.description,
53-
};
13+
return source.generateParams()
14+
.filter((p) => p.lang === 'zh')
15+
.map(({ slug }) => ({ slug }));
5416
}

0 commit comments

Comments
 (0)