Skip to content

Commit

Permalink
feat: support internationalization of document content and delete use…
Browse files Browse the repository at this point in the history
…less sample files
  • Loading branch information
sun0225SUN committed Jan 31, 2025
1 parent 2e56230 commit 6d706ec
Show file tree
Hide file tree
Showing 45 changed files with 213 additions and 1,429 deletions.
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["biomejs.biome", "unifiedjs.vscode-mdx"]
}
40 changes: 38 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,44 @@
{
"editor.codeActionsOnSave": {
"quickfix.biome": "explicit",
"source.organizeImports.biome": "explicit",
"quickfix.biome": "explicit"
"source.formatDocument.biome": "explicit"
},
"editor.defaultFormatter": "biomejs.biome",
"editor.formatOnSave": true,
"eslint.enable": false,
"prettier.enable": false
"prettier.enable": false,
"[typescriptreact]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[typescript]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[javascript]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[javascriptreact]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[json]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[jsonc]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[cjs]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[mjs]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[cts]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[mts]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[css]": {
"editor.defaultFormatter": "biomejs.biome"
}
}
2 changes: 1 addition & 1 deletion lefthook.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pre-commit:
commands:
check:
glob: "*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc}"
glob: "*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc,css}"
run: npx @biomejs/biome check --write --no-errors-on-unmatched --files-ignore-unknown=true --colors=off {staged_files}
stage_fixed: true
4 changes: 4 additions & 0 deletions next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const withNextra = nextra({

export default withNextra({
reactStrictMode: true,
i18n: {
locales: ['en', 'zh'],
defaultLocale: 'en',
},
// https://github.com/vercel/turborepo/issues/4832#issuecomment-1751407444
webpack(config) {
config.module.rules.push({
Expand Down
Binary file removed public/demo.png
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ import { useMDXComponents } from '~/mdx-components'

export const generateStaticParams = generateStaticParamsFor('mdxPath')

// @ts-ignore
export async function generateMetadata(props) {
export async function generateMetadata(props: PageProps) {
const params = await props.params
const { metadata } = await importPage(params.mdxPath)
const { metadata } = await importPage(params.mdxPath, params.lang)
return metadata
}

type PageProps = Readonly<{
params: Promise<{
mdxPath: string[]
lang: string
}>
}>
const Wrapper = useMDXComponents().wrapper

// @ts-ignore
export default async function Page(props) {
export default async function Page(props: PageProps) {
const params = await props.params
const result = await importPage(params.mdxPath)
const result = await importPage(params.mdxPath, params.lang)
const { default: MDXContent, toc, metadata } = result
return (
<Wrapper
Expand Down
90 changes: 90 additions & 0 deletions src/app/[lang]/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { Footer, LastUpdated, Layout, Navbar } from 'nextra-theme-docs'
import { Banner, Head } from 'nextra/components'
import { getPageMap } from 'nextra/page-map'
import 'nextra-theme-docs/style.css'
import type { ReactNode } from 'react'
import { Logo } from '~/components/logo'
import '~/styles/globals.css'
import type { Locale } from '~/i18n/config'
import { getDictionary } from '~/i18n/routing'

export const metadata = {
metadataBase: new URL('https://createwise.ai'),
favicon: '/favicon.ico',
title: {
template: '%s - CreateWise',
},
description: 'CreateWise Docs',
}

export default async function RootLayout({
children,
params,
}: { children: ReactNode; params: Promise<{ lang: string }> }) {
const { lang } = await params

const dict = await getDictionary(lang as Locale)
const pageMap = await getPageMap(`/${lang}`)

const banner = () => {
return (
<Banner storageKey='1.0-beta'>
<div className=''>
<a
href='https://createwise.ai'
target='_blank'
rel='noreferrer'
>
🎉 CreateWise 1.0 beta is released. Read more →
</a>
</div>
</Banner>
)
}

const navbar = () => {
return (
<Navbar
logo={<Logo />}
chatLink='https://discord.gg/p7kWbxDx'
/>
)
}

return (
<html
lang={lang}
suppressHydrationWarning
>
<Head />
<body>
<Layout
banner={banner()}
navbar={navbar()}
footer={<Footer />}
docsRepositoryBase='https://github.com/CreateWise/createwise-docs'
editLink={dict.editPage}
sidebar={{ defaultMenuCollapseLevel: 2 }}
pageMap={pageMap}
lastUpdated={<LastUpdated>{dict.lastUpdated}</LastUpdated>}
i18n={[
{ locale: 'en', name: 'English' },
{ locale: 'zh', name: '简体中文' },
]}
themeSwitch={{
dark: dict.dark,
light: dict.light,
system: dict.system,
}}
nextThemes={{ defaultTheme: 'system' }}
feedback={{
content: dict.feedback,
labels: '',
}}
>
{children}
</Layout>
</body>
</html>
)
}
1 change: 1 addition & 0 deletions src/app/[lang]/not-found.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { NotFoundPage as default } from 'nextra-theme-docs'
54 changes: 0 additions & 54 deletions src/app/layout.tsx

This file was deleted.

7 changes: 0 additions & 7 deletions src/content/_meta.js

This file was deleted.

56 changes: 0 additions & 56 deletions src/content/advanced/code-highlighting.mdx

This file was deleted.

5 changes: 5 additions & 0 deletions src/content/en/_meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
index: 'Introduction',
guide: 'Guide',
advanced: 'Advanced',
}
1 change: 1 addition & 0 deletions src/content/en/advanced/demo.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Todo 2
3 changes: 3 additions & 0 deletions src/content/en/guide/_meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
demo: '',
}
1 change: 1 addition & 0 deletions src/content/en/guide/demo.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Todo 1
1 change: 1 addition & 0 deletions src/content/en/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Introduction
8 changes: 0 additions & 8 deletions src/content/features/_meta.js

This file was deleted.

54 changes: 0 additions & 54 deletions src/content/features/i18n.mdx

This file was deleted.

Loading

0 comments on commit 6d706ec

Please sign in to comment.