Skip to content

Commit c96659d

Browse files
committed
feat: support i18n
1 parent d73ac7f commit c96659d

File tree

21 files changed

+138
-62
lines changed

21 files changed

+138
-62
lines changed

app/[[...mdxPath]]/page.jsx renamed to app/[lang]/[[...mdxPath]]/page.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { generateStaticParamsFor, importPage } from 'nextra/pages'
2-
import { useMDXComponents as getMDXComponents } from '../../mdx-components'
2+
import { useMDXComponents as getMDXComponents } from '../../../mdx-components'
33

44
export const generateStaticParams = generateStaticParamsFor('mdxPath')
55

66
export async function generateMetadata(props) {
77
const params = await props.params
8-
const { metadata } = await importPage(params.mdxPath)
8+
const { metadata } = await importPage(params.mdxPath, params.lang)
99
return metadata
1010
}
1111

1212
const Wrapper = getMDXComponents().wrapper
1313

1414
export default async function Page(props) {
1515
const params = await props.params
16-
const result = await importPage(params.mdxPath)
16+
const result = await importPage(params.mdxPath, params.lang)
1717
const { default: MDXContent, toc, metadata } = result
1818
return (
1919
<Wrapper toc={toc} metadata={metadata}>

app/components/logo-title.jsx renamed to app/[lang]/components/logo-title.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Image from "next/image";
22
import styles from "../styles/logo-title.module.css";
3-
import logo from "../../public/images/icons/Logo_128x128.png";
3+
import logo from "../../../public/images/icons/Logo_128x128.png";
44

55
export const TitleShort = (props) => {
66
return (

app/[lang]/layout.jsx

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { Footer, Layout, Navbar, LocaleSwitch } from 'nextra-theme-docs'
2+
import { TitleFullWithLogo } from './components/logo-title'
3+
import { Head } from 'nextra/components'
4+
import { getPageMap } from 'nextra/page-map'
5+
import 'nextra-theme-docs/style.css'
6+
7+
export const metadata = {
8+
applicationName: 'SJMCL',
9+
appleWebApp: {
10+
title: 'SJMCL Docs'
11+
},
12+
metadataBase: new URL('https://mc.sjtu.cn/sjmcl'),
13+
other: {
14+
'msapplication-TileColor': '#fff'
15+
},
16+
title: {
17+
default: 'SJMC Launcher',
18+
template: '%s | SJMCL'
19+
},
20+
}
21+
22+
const navbar = (
23+
<Navbar
24+
logo={<TitleFullWithLogo />}
25+
projectLink="https://github.com/UNIkeEN/SJMCL"
26+
>
27+
<LocaleSwitch />
28+
</Navbar>
29+
)
30+
const footer = (
31+
<Footer>
32+
沪 ICP 备 05052060 号-7
33+
<br/>
34+
{new Date().getFullYear()} © SJMCL Team.
35+
</Footer>
36+
)
37+
38+
export default async function RootLayout({ children, params }) {
39+
const { lang } = await params
40+
let pageMap = await getPageMap(`/${lang}`)
41+
42+
return (
43+
<html
44+
// Not required, but good for SEO
45+
lang="en"
46+
// Required to be set
47+
dir="ltr"
48+
// Suggested by `next-themes` package https://github.com/pacocoursey/next-themes#with-app
49+
suppressHydrationWarning
50+
>
51+
<Head
52+
// ... Your additional head options
53+
>
54+
{/* Your additional tags should be passed as `children` of `<Head>` element */}
55+
</Head>
56+
<body>
57+
<Layout
58+
// banner={banner}
59+
navbar={navbar}
60+
pageMap={pageMap}
61+
docsRepositoryBase="https://github.com/UNIkeEN/SJMCL/tree/main"
62+
footer={footer}
63+
i18n={[
64+
{ locale: 'en', name: 'English' },
65+
{ locale: 'zh', name: '中文' }
66+
]}
67+
>
68+
{children}
69+
</Layout>
70+
</body>
71+
</html>
72+
)
73+
}
File renamed without changes.

app/layout.jsx

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,3 @@
1-
import { Footer, Layout, Navbar } from 'nextra-theme-docs'
2-
import { TitleFullWithLogo } from './components/logo-title'
3-
import { Head } from 'nextra/components'
4-
import { getPageMap } from 'nextra/page-map'
5-
import 'nextra-theme-docs/style.css'
6-
7-
export const metadata = {
8-
applicationName: 'SJMCL',
9-
appleWebApp: {
10-
title: 'SJMCL Docs'
11-
},
12-
metadataBase: new URL('https://mc.sjtu.cn/sjmcl'),
13-
other: {
14-
'msapplication-TileColor': '#fff'
15-
},
16-
title: {
17-
default: 'SJMC Launcher',
18-
template: '%s | SJMCL'
19-
},
1+
export default function RootLayout({ children }) {
2+
return children
203
}
21-
22-
// const banner = <Banner storageKey="some-key">Nextra 4.0 is released 🎉</Banner>
23-
const navbar = (
24-
<Navbar
25-
logo={<TitleFullWithLogo />}
26-
projectLink="https://github.com/UNIkeEN/SJMCL"
27-
/>
28-
)
29-
const footer = <Footer>{new Date().getFullYear()} © SJMCL Team.</Footer>
30-
31-
export default async function RootLayout({ children }) {
32-
return (
33-
<html
34-
// Not required, but good for SEO
35-
lang="en"
36-
// Required to be set
37-
dir="ltr"
38-
// Suggested by `next-themes` package https://github.com/pacocoursey/next-themes#with-app
39-
suppressHydrationWarning
40-
>
41-
<Head
42-
// ... Your additional head options
43-
>
44-
{/* Your additional tags should be passed as `children` of `<Head>` element */}
45-
</Head>
46-
<body>
47-
<Layout
48-
// banner={banner}
49-
navbar={navbar}
50-
pageMap={await getPageMap()}
51-
docsRepositoryBase="https://github.com/UNIkeEN/SJMCL/tree/main"
52-
footer={footer}
53-
>
54-
{children}
55-
</Layout>
56-
</body>
57-
</html>
58-
)
59-
}

app/page.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { redirect } from 'next/navigation'
2+
3+
export default function Home() {
4+
redirect('/zh')
5+
return <></>
6+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)