quinnz commited on
Commit
8a7d317
·
1 Parent(s): 694422f

fix error

Browse files
app/.DS_Store ADDED
Binary file (6.15 kB). View file
 
app/[lang]/[...slug]/page.tsx CHANGED
@@ -1,5 +1,7 @@
1
  import { notFound } from 'next/navigation'
2
- import dynamic from 'next/dynamic'
 
 
3
  import { getMdxPath, mdxExists } from '@/lib/mdx'
4
 
5
  export default async function DocPage({ params }: { params: { lang: string; slug: string[] } }) {
@@ -8,9 +10,11 @@ export default async function DocPage({ params }: { params: { lang: string; slug
8
 
9
  if (!mdxExists(mdxPath)) notFound()
10
 
11
- const Page = dynamic(() =>
12
- import(`@/content/${lang}/${slug.join('/')}.mdx`).then(mod => mod.default)
13
- )
14
 
15
- return <Page />
 
 
 
 
16
  }
 
1
  import { notFound } from 'next/navigation'
2
+ import { MDXRemote } from 'next-mdx-remote/rsc'
3
+ import fs from 'fs'
4
+ import path from 'path'
5
  import { getMdxPath, mdxExists } from '@/lib/mdx'
6
 
7
  export default async function DocPage({ params }: { params: { lang: string; slug: string[] } }) {
 
10
 
11
  if (!mdxExists(mdxPath)) notFound()
12
 
13
+ const source = fs.readFileSync(mdxPath, 'utf-8')
 
 
14
 
15
+ return (
16
+ <main className="prose mx-auto">
17
+ <MDXRemote source={source} />
18
+ </main>
19
+ )
20
  }
app/[lang]/page.tsx CHANGED
@@ -1,19 +1,21 @@
1
  // app/[lang]/page.tsx
2
  import { notFound } from 'next/navigation'
3
- import dynamic from 'next/dynamic'
 
 
4
 
5
  export default async function LangIndex({ params }: { params: { lang: string } }) {
6
  const { lang } = params
7
  if (!['zh','en'].includes(lang)) notFound()
8
 
9
- // 动态 import + await 生产安全
10
- const Page = dynamic(() =>
11
- import(`../../content/${lang}/index.mdx`).then(mod => mod.default)
12
- )
13
 
14
  return (
15
  <main className="prose mx-auto">
16
- <Page />
17
  </main>
18
  )
19
  }
 
1
  // app/[lang]/page.tsx
2
  import { notFound } from 'next/navigation'
3
+ import { MDXRemote } from 'next-mdx-remote/rsc'
4
+ import fs from 'fs'
5
+ import path from 'path'
6
 
7
  export default async function LangIndex({ params }: { params: { lang: string } }) {
8
  const { lang } = params
9
  if (!['zh','en'].includes(lang)) notFound()
10
 
11
+ const mdxPath = path.join(process.cwd(), 'content', lang, 'index.mdx')
12
+ if (!fs.existsSync(mdxPath)) notFound()
13
+
14
+ const source = fs.readFileSync(mdxPath, 'utf-8')
15
 
16
  return (
17
  <main className="prose mx-auto">
18
+ <MDXRemote source={source} />
19
  </main>
20
  )
21
  }
app/basics/.DS_Store ADDED
Binary file (6.15 kB). View file
 
app/basics/[...slug]/page.tsx ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { MDXRemote } from 'next-mdx-remote/rsc'
2
+ import fs from 'fs'
3
+ import path from 'path'
4
+ import { notFound } from 'next/navigation'
5
+
6
+ export default async function BasicsDocPage({ params }: { params: { slug: string[] } }) {
7
+ const { slug } = params
8
+ // 默认使用英文的文档
9
+ const mdxPath = path.join(process.cwd(), 'content', 'en', 'basics', ...slug) + '.mdx'
10
+
11
+ if (!fs.existsSync(mdxPath)) {
12
+ notFound()
13
+ }
14
+
15
+ const source = fs.readFileSync(mdxPath, 'utf-8')
16
+
17
+ return (
18
+ <main className="prose mx-auto">
19
+ <MDXRemote source={source} />
20
+ </main>
21
+ )
22
+ }
app/basics/page.tsx ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { MDXRemote } from 'next-mdx-remote/rsc'
2
+ import fs from 'fs'
3
+ import path from 'path'
4
+ import { notFound } from 'next/navigation'
5
+
6
+ export default async function BasicsPage() {
7
+ // 默认使用英文的 basics 页面
8
+ const mdxPath = path.join(process.cwd(), 'content', 'en', 'basics', 'index.mdx')
9
+
10
+ if (!fs.existsSync(mdxPath)) {
11
+ notFound()
12
+ }
13
+
14
+ const source = fs.readFileSync(mdxPath, 'utf-8')
15
+
16
+ return (
17
+ <main className="prose mx-auto">
18
+ <MDXRemote source={source} />
19
+ </main>
20
+ )
21
+ }
app/layout.tsx ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ export default function RootLayout({ children }: { children: React.ReactNode }) {
2
+ return (
3
+ <html>
4
+ <body>{children}</body>
5
+ </html>
6
+ )
7
+ }
app/page.tsx ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { MDXRemote } from 'next-mdx-remote/rsc'
2
+ import fs from 'fs'
3
+ import path from 'path'
4
+
5
+ export default function RootPage() {
6
+ const mdxPath = path.join(process.cwd(), 'content', 'en', 'index.mdx')
7
+ const source = fs.readFileSync(mdxPath, 'utf-8')
8
+
9
+ return (
10
+ <main className="prose mx-auto">
11
+ <MDXRemote source={source} />
12
+ </main>
13
+ )
14
+ }
content/en/index.mdx CHANGED
@@ -1,3 +1,7 @@
1
  # AI Knowledge Base (EN)
2
 
3
- Welcome to the enterprise AI knowledge base.
 
 
 
 
 
1
  # AI Knowledge Base (EN)
2
 
3
+ Welcome to the enterprise AI knowledge base.
4
+
5
+ ## Topics
6
+
7
+ - [Machine Learning](/basics/machine-learning)
content/zh/index.mdx CHANGED
@@ -1,3 +1,7 @@
1
  # AI 知识库(中文)
2
 
3
- 欢迎来到企业级 AI 知识库。
 
 
 
 
 
1
  # AI 知识库(中文)
2
 
3
+ 欢迎来到企业级 AI 知识库。
4
+
5
+ ## 主题
6
+
7
+ - [机器学习](/basics/machine-learning) | [English Version](/en/basics/machine-learning)
next.config.mjs CHANGED
@@ -1,15 +1,13 @@
1
  import path from 'path'
2
- import withMDX from '@next/mdx'
3
 
4
  /** @type {import('next').NextConfig} */
5
- const nextConfig = withMDX({
6
- extension: /\.mdx?$/,
7
  pageExtensions: ['ts', 'tsx', 'mdx'],
8
  webpack(config) {
9
  // @ 绝对路径指向根目录
10
  config.resolve.alias['@'] = path.resolve(process.cwd())
11
  return config
12
  }
13
- })
14
 
15
  export default nextConfig
 
1
  import path from 'path'
 
2
 
3
  /** @type {import('next').NextConfig} */
4
+ const nextConfig = {
 
5
  pageExtensions: ['ts', 'tsx', 'mdx'],
6
  webpack(config) {
7
  // @ 绝对路径指向根目录
8
  config.resolve.alias['@'] = path.resolve(process.cwd())
9
  return config
10
  }
11
+ }
12
 
13
  export default nextConfig
package.json CHANGED
@@ -8,10 +8,12 @@
8
  },
9
  "dependencies": {
10
  "next": "^14.2.0",
 
11
  "react": "^18.2.0",
12
- "react-dom": "^18.2.0",
13
- "@next/mdx": "^14.2.0",
14
- "@mdx-js/loader": "^3.0.0",
15
- "@mdx-js/react": "^3.0.0"
 
16
  }
17
  }
 
8
  },
9
  "dependencies": {
10
  "next": "^14.2.0",
11
+ "next-mdx-remote": "^5.0.0",
12
  "react": "^18.2.0",
13
+ "react-dom": "^18.2.0"
14
+ },
15
+ "devDependencies": {
16
+ "@types/node": "25.0.10",
17
+ "typescript": "5.9.3"
18
  }
19
  }
tsconfig.json CHANGED
@@ -2,11 +2,17 @@
2
  "compilerOptions": {
3
  "baseUrl": ".",
4
  "paths": {
5
- "@/*": ["./*"]
 
 
6
  },
7
  "target": "esnext",
8
  "module": "esnext",
9
- "lib": ["dom", "dom.iterable", "esnext"],
 
 
 
 
10
  "allowJs": true,
11
  "skipLibCheck": true,
12
  "strict": true,
@@ -16,8 +22,22 @@
16
  "moduleResolution": "node",
17
  "resolveJsonModule": true,
18
  "isolatedModules": true,
19
- "jsx": "preserve"
 
 
 
 
 
 
20
  },
21
- "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "**/*.mdx"],
22
- "exclude": ["node_modules"]
23
- }
 
 
 
 
 
 
 
 
 
2
  "compilerOptions": {
3
  "baseUrl": ".",
4
  "paths": {
5
+ "@/*": [
6
+ "./*"
7
+ ]
8
  },
9
  "target": "esnext",
10
  "module": "esnext",
11
+ "lib": [
12
+ "dom",
13
+ "dom.iterable",
14
+ "esnext"
15
+ ],
16
  "allowJs": true,
17
  "skipLibCheck": true,
18
  "strict": true,
 
22
  "moduleResolution": "node",
23
  "resolveJsonModule": true,
24
  "isolatedModules": true,
25
+ "jsx": "preserve",
26
+ "incremental": true,
27
+ "plugins": [
28
+ {
29
+ "name": "next"
30
+ }
31
+ ]
32
  },
33
+ "include": [
34
+ "next-env.d.ts",
35
+ "**/*.ts",
36
+ "**/*.tsx",
37
+ "**/*.mdx",
38
+ ".next/types/**/*.ts"
39
+ ],
40
+ "exclude": [
41
+ "node_modules"
42
+ ]
43
+ }