Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 15 additions & 7 deletions app/layout.tsx → app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import type { Metadata } from "next";
import localFont from "next/font/local";
import { RootProvider } from "fumadocs-ui/provider";
import Script from "next/script";
import "./globals.css";
import { ThemeProvider } from "@/app/components/ThemeProvider";
import "../globals.css";
import { ThemeProvider } from "../components/ThemeProvider";
import { locales } from "@/i18n";

const geistSans = localFont({
src: "./fonts/GeistVF.woff",
src: "../fonts/GeistVF.woff",
variable: "--font-geist-sans",
weight: "100 900",
});
const geistMono = localFont({
src: "./fonts/GeistMonoVF.woff",
src: "../fonts/GeistMonoVF.woff",
variable: "--font-geist-mono",
weight: "100 900",
});
Expand All @@ -21,13 +22,20 @@ export const metadata: Metadata = {
description: "A modern documentation site built with Fumadocs",
};

export default function RootLayout({
export function generateStaticParams() {
return locales.map((locale) => ({ locale }));
}

export default async function RootLayout({
children,
params,
}: Readonly<{
children: React.ReactNode;
params: Promise<{ locale: string }>;
}>) {
const { locale } = await params;
return (
<html lang="en" suppressHydrationWarning>
<html lang={locale} suppressHydrationWarning>
<head>
<link rel="preload" href="/mascot.webp" as="image" type="image/webp" />
<link rel="preload" href="/mascot.png" as="image" type="image/png" />
Expand All @@ -44,7 +52,7 @@ export default function RootLayout({
// Use static index so it works in `next export` and dev.
options: {
type: "static",
api: "/search.json",
api: `/${locale}/search.json`,
},
}}
>
Expand Down
17 changes: 17 additions & 0 deletions app/[locale]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Header } from "../components/Header";
import { Hero } from "../components/Hero";
import { Features } from "../components/Features";
import { Community } from "../components/Community";
import { Footer } from "../components/Footer";

export default function DocsIndex() {
return (
<>
<Header />
<Hero />
<Features />
<Community />
<Footer />
</>
);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createFromSource } from "fumadocs-core/search/server";
import { source } from "@/lib/source";
import { createTokenizer } from "@orama/tokenizers/mandarin";
import { locales } from "@/i18n";

// Ensure this route is statically generated during `next export`.
export const dynamic = "force-static";
Expand All @@ -16,3 +17,7 @@ const api = createFromSource(source, {
},
});
export const GET = api.staticGET;

export function generateStaticParams() {
return locales.map((locale) => ({ locale }));
}
17 changes: 0 additions & 17 deletions app/page.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions scripts/check-images.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* MDX 图片路径校验脚本
*
* 功能
* - 扫描 `app/docs/??/?.mdx`(含 .md)
* - 扫描 `app/[locale]/docs/??/?.mdx`(含 .md)
* - 识别 Markdown `![]()` 与内联 `<img src="…" />` 的图片引用
* - 强制使用“就近图片”:推荐相对路径(如 `./images/…`)
* - 仅对站点级共享资源允许绝对路径:`/images/site/*`、`/images/components/*`
Expand All @@ -25,7 +25,7 @@ import fs from "fs";
import path from "path";

const ROOT = process.cwd();
const DOCS_DIR = path.join(ROOT, "app", "docs");
const DOCS_DIR = path.join(ROOT, "app", "[locale]", "docs");
// 允许的绝对路径前缀(站点级 & 组件演示级别)
const ALLOWED_ABSOLUTE_PREFIXES = ["/images/site/", "/images/components/"];

Expand Down
4 changes: 2 additions & 2 deletions scripts/move-doc-images.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* MDX 图片就近迁移脚本(中文注释)
*
* 目标
* - 扫描 `app/docs/??/?.mdx`(含 .md)里的图片引用
* - 扫描 `app/[locale]/docs/??/?.mdx`(含 .md)里的图片引用
* - 对于以 `/images/...` 绝对路径引用且仅被“单一文档”使用的图片:移动到对应 MDX 同目录下的 `images/` 子目录
* - 同时将文中的绝对路径替换为相对路径 `./images/<文件名>`(站点级资源除外)
*
Expand All @@ -27,7 +27,7 @@ import crypto from "crypto";

// 仓库根目录、文档目录与 public 目录
const ROOT = process.cwd();
const DOCS_DIR = path.join(ROOT, "app", "docs");
const DOCS_DIR = path.join(ROOT, "app", "[locale]", "docs");
const PUBLIC_DIR = path.join(ROOT, "public");

// 排除不迁移的绝对路径前缀(站点级 & 组件演示级别)
Expand Down
2 changes: 1 addition & 1 deletion source.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineDocs, defineConfig } from "fumadocs-mdx/config";

export const docs = defineDocs({
dir: "app/docs",
dir: "app/[locale]/docs",
Comment on lines 1 to +4

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Update docs baseUrl to include locale prefix

Renaming the docs tree to app/[locale]/docs means every docs page now lives under a locale segment, but the Fumadocs loader still uses baseUrl: "/docs" in lib/source.ts. Components like DocsLayout and the search index build URLs by concatenating this base URL, so links and search results will continue to point at /docs/... while the actual routes are /en/docs/..., /zh/docs/..., etc. Navigation for all non-default paths will 404 after this commit. The base URL should be made locale-aware (e.g. prefixed with the current locale) alongside this directory move.

Useful? React with 👍 / 👎.

});

export default defineConfig();