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
40 changes: 40 additions & 0 deletions add-i18-test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## work repoter
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix typo in title.

Line 1 contains a spelling error: "repoter" should be "reporter".

-## work repoter
+## Work Report

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 LanguageTool

[grammar] ~1-~1: Ensure spelling is correct
Context: ## work repoter I am try to reading the nextra/next.js &...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)

🤖 Prompt for AI Agents
In add-i18-test.md around lines 1 to 1, the title contains a typo ("work
repoter"); update the text to "work reporter" by correcting the misspelled word
so the heading reads "## work reporter".


I am try to reading the nextra/next.js & i18n official docs to add a touch-down button on zetachain docs. Help users can click to switch en & zh, and other languages.
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Improve awkward phrasing.

Line 3 contains ungrammatical text. Revise for clarity and correctness.

-I am try to reading the nextra/next.js & i18n official docs to add a touch-down button on zetachain docs. Help users can click to switch en & zh, and other languages.
+I am trying to read the Nextra/Next.js & i18n official documentation to add a language-switch button to the ZetaChain docs, enabling users to switch between English & Chinese, and potentially other languages.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
I am try to reading the nextra/next.js & i18n official docs to add a touch-down button on zetachain docs. Help users can click to switch en & zh, and other languages.
I am trying to read the Nextra/Next.js & i18n official documentation to add a language-switch button to the ZetaChain docs, enabling users to switch between English & Chinese, and potentially other languages.
🤖 Prompt for AI Agents
In add-i18-test.md around line 3, the sentence is ungrammatical and awkward ("I
am try to reading the nextra/next.js & i18n official docs to add a touch-down
button on zetachain docs. Help users can click to switch en & zh, and other
languages."); rewrite it for clarity and correct grammar — e.g. state that you
reviewed Nextra/Next.js and i18n docs and implemented a language toggle on the
ZetaChain docs so users can switch between English, Chinese, and other
languages; keep it concise and use proper verbs and punctuation.


### reading
- https://github.com/shuding/nextra/blob/main/packages/nextra-theme-docs/src/components/locale-switch.tsx
- https://nextra-v2-oe0zrpzjp-shud.vercel.app/docs/guide/i18n

denis dev a demo to help me understand how i18n work, I have been read.
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Clarify awkward phrasing.

Line 9 would be clearer if revised.

-denis dev a demo to help me understand how i18n work, I have been read.
+Denis created a demo to help me understand how i18n works; I have reviewed it.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
denis dev a demo to help me understand how i18n work, I have been read.
Denis created a demo to help me understand how i18n works; I have reviewed it.
🤖 Prompt for AI Agents
In add-i18-test.md around line 9, the sentence "denis dev a demo to help me
understand how i18n work, I have been read." is awkward and unclear; rewrite it
to use correct grammar and clearer meaning — for example, use proper
capitalization, verbs and plurality ("Denis developed a demo to help me
understand how i18n works; I have read it.") or a similar concise, grammatically
correct sentence that matches the intended message.


- https://docs-v2-git-feat-i18n.zetachain.app/start/app
- https://docs-v2-git-feat-i18n.zetachain.app/zh-CN/start/app

### developing
[2025.11.19 09:29] I have been modify `next.config.js` and `/src/theme.config.tsx` to add i18n languages switch feature. testing in cloud server always downtime, so I use my local pc try again.
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Improve grammar in timestamp entry.

Line 15 contains grammatical issues. Consider revising for clarity.

-[2025.11.19 09:29] I have been modify `next.config.js` and `/src/theme.config.tsx` to add i18n languages switch feature. testing in cloud server always downtime, so I use my local pc try again.
+[2025.11.19 09:29] I modified `next.config.js` and `/src/theme.config.tsx` to add i18n language-switch features. Cloud server testing was consistently unavailable, so I tested locally on my machine instead.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
[2025.11.19 09:29] I have been modify `next.config.js` and `/src/theme.config.tsx` to add i18n languages switch feature. testing in cloud server always downtime, so I use my local pc try again.
[2025.11.19 09:29] I modified `next.config.js` and `/src/theme.config.tsx` to add i18n language-switch features. Cloud server testing was consistently unavailable, so I tested locally on my machine instead.
🤖 Prompt for AI Agents
In add-i18-test.md around line 15, the timestamp entry sentence is grammatically
incorrect; replace "[2025.11.19 09:29] I have been modify `next.config.js` and
`/src/theme.config.tsx` to add i18n languages switch feature. testing in cloud
server always downtime, so I use my local pc try again." with a corrected
version such as "[2025.11.19 09:29] I modified `next.config.js` and
`/src/theme.config.tsx` to add an i18n language switch feature. Testing on the
cloud server caused downtime, so I retried locally on my PC." Ensure
capitalization, verb tense, and article use are fixed.


[2025.11.19 15:15] in macmini is successfully add i18n. I match the en & zh pages:

- [x] about
- [x] developers
- [x] nodes
- [x] reference
- [x] start
- [x] users

I add the nextra LocaleSwitch to switch languages, now is support en & zh.
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Improve sentence structure and capitalization.

Line 26 would benefit from clearer phrasing and proper capitalization.

-I add the nextra LocaleSwitch to switch languages, now is support en & zh.
+I added the Nextra LocaleSwitch component to enable language switching; English (en-US) and Chinese (zh-CN) are now supported.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
I add the nextra LocaleSwitch to switch languages, now is support en & zh.
I added the Nextra LocaleSwitch component to enable language switching; English (en-US) and Chinese (zh-CN) are now supported.
🧰 Tools
🪛 LanguageTool

[grammar] ~26-~26: Ensure spelling is correct
Context: ...ence - [x] start - [x] users I add the nextra LocaleSwitch to switch languages, now i...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)

🤖 Prompt for AI Agents
In add-i18-test.md around line 26, the sentence is awkward and incorrectly
capitalized; replace it with a clearer, properly capitalized sentence such as:
"I added the Nextra LocaleSwitch to enable language switching; it now supports
English and Chinese." Ensure "Nextra LocaleSwitch" is capitalized and use
"English" and "Chinese" rather than "en" & "zh".


in `src` add the new file `middleware.js`, will help to match the files path.

every english docs is named `xxx.en-US`, every chinese docs is named `xxx.zh-CN`.

but now have three questions in this branch.

1. <del>the sidebar is not turn with the language switch</del>
2. <del>when user click someone page, the sidebar is not highlight.</del>
3. in nextra setting, `index.en-US` or `index.zh-CN` will be redirect to the father path, but the true path is the children. such as view `http://localhost:3001/zh-CN/developers/evm` is 404 not found. I am check the problem, but need some times.

[2025.11.21 10:29] I solve the sidebar highlight issue, add a path compare tool `router.ts` in `src/lib/helpers`. the router.pathname is different from page.route, so need a tool to remove the prefix for locale and make a standard router format.

[2025.11.21 12:56] I solve the sidebar en & zh switch, and make sure the folders and files name is true.
Comment on lines +38 to +40
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Improve grammar and technical terminology in progress notes.

Lines 38–40 contain grammatical issues and could be more precise. Consider revising for consistency with other professional documentation.

-[2025.11.21 10:29] I solve the sidebar highlight issue, add a path compare tool `router.ts` in `src/lib/helpers`. the router.pathname is different from page.route, so need a tool to remove the prefix for locale and make a standard router format.
+[2025.11.21 10:29] I resolved the sidebar highlight issue by adding a path normalization utility (`router.ts`) in `src/lib/helpers`. The `router.pathname` differs from `page.route`, so the utility removes the locale prefix to standardize the router format.
-[2025.11.21 12:56] I solve the sidebar en & zh switch, and make sure the folders and files name is true.
+[2025.11.21 12:56] I resolved the sidebar language switching for both English and Chinese, and verified that folder and file naming conventions are correct.
🤖 Prompt for AI Agents
add-i18-test.md lines 38–40: the progress notes are grammatically awkward and
use inconsistent technical terms; replace the two sentences with clearer,
professional wording such as: "2025-11-21 10:29 — Fixed the sidebar highlight
issue and added a path comparison utility (src/lib/helpers/router.ts). The
utility normalizes routes by removing locale prefixes so router.pathname and
page.route share a standard format." and "2025-11-21 12:56 — Resolved sidebar
English/Chinese switching and verified that folder and file names are correct."
Ensure consistent timestamp format, use active verbs, and prefer precise
technical terms like "path comparison utility", "normalize routes", and
"verified" for clarity.

11 changes: 11 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ const baseNextConfig = {
*/
serverSourceMaps: false,
},
i18n: {
locales: ["en-US", "zh-CN"],
defaultLocale: "en-US",
localeDetection: false,
},
trailingSlash: true,
basePath: process.env.NEXT_PUBLIC_BASE_PATH,
// This is required to support PostHog trailing slash API requests
Expand Down Expand Up @@ -59,6 +64,12 @@ const baseNextConfig = {
port: "",
pathname: "/jmvpciyouqsr/**", // production space id
},
{
protocol: "https",
hostname: "images.ctfassets.net",
port: "",
pathname: "/ouogysw2n3om/**", // add new space id for testing
},
{
protocol: "http",
hostname: "localhost",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Accordion, AccordionDetails, AccordionSummary, Typography } from "@mui/material";
import { isPathMatch, normalizePath } from "~/lib/helpers/router"; //导入工具函数
import clsx from "clsx";
import Link from "next/link";
import { useRouter } from "next/router";
import { Page } from "nextra";
import { PropsWithChildren, useEffect, useMemo, useState } from "react";
import tw, { styled } from "twin.macro";

import { getPageTitle } from "~/lib/helpers/nextra";
import { getPageTitle,getPageTitleWithLocale } from "~/lib/helpers/nextra";

import { IconDropDown } from "../../Icons";

Expand All @@ -28,8 +29,18 @@ type NavigationAccordionLinkProps = PropsWithChildren<{

const NavigationAccordion: React.FC<NavigationAccordionLinkProps> = ({ page, children }) => {
const router = useRouter();
const isRouteInAccordion = router.pathname.includes(page.route);
//const isRouteInAccordion = router.pathname.includes(page.route);
const normalizedPathname = normalizePath(router.asPath || router.pathname);

// console.log('🔵 当前页面 meta:', {
// route: page.route,
// title: page.meta?.title,
// locale: (page as any).locale,
// });

const normalizedPageRoute = normalizePath(page.route);
const isRouteInAccordion = normalizedPathname.startsWith(normalizedPageRoute) || normalizedPathname === normalizedPageRoute;

const [expanded, setExpanded] = useState<string | false>(isRouteInAccordion ? page.route : false);

const handleChange = (route: string) => (_event: React.SyntheticEvent, isExpanded: boolean) =>
Expand Down Expand Up @@ -59,7 +70,7 @@ const NavigationAccordion: React.FC<NavigationAccordionLinkProps> = ({ page, chi
"text-grey-500 dark:text-white": expanded,
})}
>
{getPageTitle(page)}
{getPageTitleWithLocale(page, router.locale)}
</div>
</AccordionSummary>

Expand All @@ -70,8 +81,8 @@ const NavigationAccordion: React.FC<NavigationAccordionLinkProps> = ({ page, chi

export const NavigationAccordionLink: React.FC<NavigationAccordionLinkProps> = ({ page, onClick, isTopLevelPage }) => {
const router = useRouter();
const isRouteSelected = router.pathname === page.route;

// const isRouteSelected = router.pathname === page.route;
const isRouteSelected = isPathMatch(router.asPath || router.pathname, page.route, router);
if (page.kind !== "Folder") {
return (
<Link
Expand All @@ -92,7 +103,7 @@ export const NavigationAccordionLink: React.FC<NavigationAccordionLinkProps> = (
)}

<div className="text-base leading-[130%] sm:text-xs sm:leading-[110%] whitespace-pre-wrap text-ellipsis overflow-hidden">
{getPageTitle(page)}
{getPageTitleWithLocale(page, router.locale)}
</div>
</Link>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ListItem } from "@mui/material";
import { isPathStartWith, normalizePath } from "~/lib/helpers/router"; //导入工具函数
import clsx from "clsx";
import { useRouter } from "next/router";
import { createElement, useMemo } from "react";
Expand All @@ -21,17 +22,30 @@ export const NavigationItem = ({ item, isOpen, withLabel = true, onClick }: Navi

const router = useRouter();

// const isSelected = useMemo(() => {
// if (!url) {
// return false;
// }

// if (router.pathname === "/" || url === "/") {
// return url === router.pathname;
// }

// return router.pathname.startsWith(url);
// }, [url, router.pathname]);
const isSelected = useMemo(() => {
if (!url) {
return false;
}

if (router.pathname === "/" || url === "/") {
return url === router.pathname;

const currentPath = router.asPath || router.pathname;

if (currentPath === "/" || url === "/") {
return normalizePath(currentPath) === normalizePath(url);
}

return router.pathname.startsWith(url);
}, [url, router.pathname]);
return isPathStartWith(currentPath, url, router);
}, [url, router.asPath, router.pathname, router]);
Comment on lines 36 to +48
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix formatting issues and approve locale-aware navigation logic.

The new logic correctly handles locale-aware path matching using the introduced helper functions. However, there are formatting issues that need to be addressed.

Apply this diff to fix the ESLint prettier formatting errors:

   const isSelected = useMemo(() => {
     if (!url) {
       return false;
     }
-  
+
     const currentPath = router.asPath || router.pathname;
-    
+
     if (currentPath === "/" || url === "/") {
       return normalizePath(currentPath) === normalizePath(url);
     }
-  
+
     return isPathStartWith(currentPath, url, router);
   }, [url, router.asPath, router.pathname, router]);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const isSelected = useMemo(() => {
if (!url) {
return false;
}
if (router.pathname === "/" || url === "/") {
return url === router.pathname;
const currentPath = router.asPath || router.pathname;
if (currentPath === "/" || url === "/") {
return normalizePath(currentPath) === normalizePath(url);
}
return router.pathname.startsWith(url);
}, [url, router.pathname]);
return isPathStartWith(currentPath, url, router);
}, [url, router.asPath, router.pathname, router]);
const isSelected = useMemo(() => {
if (!url) {
return false;
}
const currentPath = router.asPath || router.pathname;
if (currentPath === "/" || url === "/") {
return normalizePath(currentPath) === normalizePath(url);
}
return isPathStartWith(currentPath, url, router);
}, [url, router.asPath, router.pathname, router]);
🧰 Tools
🪛 ESLint

[error] 40-40: Delete ··

(prettier/prettier)


[error] 42-42: Delete ····

(prettier/prettier)


[error] 46-46: Delete ··

(prettier/prettier)

🤖 Prompt for AI Agents
src/components/shared/components/Layout/components/NavigationItem.tsx lines
36-48: the updated useMemo block is functionally correct but has Prettier/ESLint
formatting issues; reformat the block to follow project style (consistent
indentation, blank lines, and semicolons where required), ensure there's a blank
line after the early return block, keep the dependency array minimal and stable
(use [url, router.asPath, router.pathname] instead of [url, router.asPath,
router.pathname, router]) and run the project's formatter/ESLint autofix to
apply the exact whitespace and semicolon changes.


return (
<ListItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,17 @@ export const NavigationLayout: React.FC<NavigationLayoutProps> = ({ isMainPage,
<List className="w-full">
{navSection.children
.filter((page) => page.route !== item.url)
// ✅ 添加去重逻辑:使用 Map 去重,只保留每个 route 的第一个页面
.reduce((acc, page) => {
if (!acc.find((p) => p.route === page.route)) {
acc.push(page);
}
return acc;
}, [] as typeof navSection.children)
.map((page) => (
<div key={page.route} className="px-3 pl-12 sm:pr-6 pb-3 sm:pb-2">
<NavigationAccordionLink
key={page.route}
// ✅ 移除重复的 key(已经在 div 上有 key 了)
page={page}
onClick={closeMobileDrawer}
isTopLevelPage
Expand Down
150 changes: 144 additions & 6 deletions src/hooks/useSetDirectoriesState.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,164 @@
// import { getAllPages } from "nextra/context";
// import { useEffect, useMemo } from "react";
// import { useRouter } from "next/router";
// import { useAppDispatch } from "../lib/app.store";
// import { setDirectories, setPages } from "../lib/directories/directories.redux";
// import { getDirectories } from "../lib/helpers/nextra";

// export const useSetDirectoriesState = () => {
// const allPages = getAllPages();
// const router = useRouter();
// // ✅ 临时日志:查看页面结构
// if (allPages.length > 0) {
// console.log('🔵 getAllPages() 返回的页面:', allPages[7]);
// }
// const { flatDirectories, directoriesByRoute } = useMemo(() => getDirectories(allPages), [allPages]);

// const dispatch = useAppDispatch();

// useEffect(() => {
// if (!allPages.length) return;

// dispatch(setPages(allPages));
// }, [allPages]);

// useEffect(() => {
// if (!flatDirectories.length || !directoriesByRoute) return;

// dispatch(setDirectories({ flatDirectories, directoriesByRoute }));
// }, [flatDirectories, directoriesByRoute]);
// };
import { getAllPages } from "nextra/context";
import { useRouter } from "next/router";
import { useEffect, useMemo } from "react";

import { useAppDispatch } from "../lib/app.store";
import { setDirectories, setPages } from "../lib/directories/directories.redux";
import { getDirectories } from "../lib/helpers/nextra";
Comment on lines +1 to 37
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

清理注释实现并修复 ESLint/Prettier/import-sort 报错

  • 第 1–30 行保留了完整的旧实现作为注释,已不再使用,建议直接删除以减少噪音并避免未来维护混淆。
  • 静态分析提示当前文件存在若干格式问题(如导入顺序与引号风格、useMemo 调用的换行等),会导致 ESLint/Prettier 失败。

建议:

  • 删除整段旧实现注释与调试日志注释,仅保留必要说明性注释。
  • 在项目根目录执行一次自动格式化(如 pnpm lint --fix 或等效命令),让 simple-import-sort 与 Prettier 统一整理导入和代码风格。

Also applies to: 66-71, 145-148, 159-164



---

🏁 Script executed:

```shell
#!/bin/bash
# Verify file existence and inspect content at specified line ranges
if [ -f "src/hooks/useSetDirectoriesState.ts" ]; then
  echo "=== File found, total lines: ==="
  wc -l src/hooks/useSetDirectoriesState.ts
  echo ""
  echo "=== Lines 1-37 (primary range): ==="
  sed -n '1,37p' src/hooks/useSetDirectoriesState.ts
  echo ""
  echo "=== Lines 66-71 (additional range): ==="
  sed -n '66,71p' src/hooks/useSetDirectoriesState.ts
  echo ""
  echo "=== Lines 145-148 (additional range): ==="
  sed -n '145,148p' src/hooks/useSetDirectoriesState.ts
  echo ""
  echo "=== Lines 159-164 (additional range): ==="
  sed -n '159,164p' src/hooks/useSetDirectoriesState.ts
else
  echo "File not found: src/hooks/useSetDirectoriesState.ts"
fi

Length of output: 2150


🏁 Script executed:

#!/bin/bash
# Check for linting configuration files and relevant eslint/prettier rules
echo "=== Checking for linting configuration: ==="
ls -la | grep -E "(eslint|prettier)" || echo "No ESLint/Prettier files in root"
echo ""
find . -maxdepth 2 -name ".eslintrc*" -o -name "prettier.config.*" -o -name ".prettierrc*" 2>/dev/null | head -10
echo ""
echo "=== Checking package.json for lint scripts: ==="
if [ -f "package.json" ]; then
  cat package.json | grep -A 5 '"scripts"' | head -15
fi

Length of output: 840


🏁 Script executed:

#!/bin/bash
# Search for commented import statements and old implementations in the file
echo "=== Checking for commented code patterns: ==="
rg -n "^\s*//\s*(import|export|const|function|useEffect|useMemo)" src/hooks/useSetDirectoriesState.ts || echo "No commented code patterns found"

Length of output: 777


🏁 Script executed:

#!/bin/bash
# Verify import sort order and formatting issues at line 1-37
echo "=== Full content with line numbers (lines 1-50): ==="
sed -n '1,50p' src/hooks/useSetDirectoriesState.ts | cat -n

Length of output: 2198


Remove dead code blocks to eliminate unnecessary noise and maintenance burden.

The extensive commented implementation (lines 1–30) along with additional commented hooks (lines 43, 138) should be deleted entirely. These represent obsolete code that has been superseded by the active implementation and serve only to obscure readability.

The imports are already correctly ordered and formatted. No refactoring of import statements or broader formatting passes are required.

Action: Delete lines 1–30 and any other commented implementation blocks (e.g., lines 43, 138) to keep the file clean and maintainable.

🧰 Tools
🪛 ESLint

[error] 31-37: Run autofix to sort these imports!

(simple-import-sort/imports)

🤖 Prompt for AI Agents
In src/hooks/useSetDirectoriesState.ts around lines 1 to 37, remove the large
commented-out implementation block (specifically delete lines 1–30) and any
other commented implementation blocks (e.g., the commented sections starting at
lines ~43 and ~138) so only the active imports and code remain; ensure you
remove only obsolete commented code, keep the current import statements intact
and run a quick formatting pass to fix spacing after deletion.


export const useSetDirectoriesState = () => {
const allPages = getAllPages();
const router = useRouter(); // 添加这一行获取当前 locale
const allPages = getAllPages();

// useEffect(() => {
// if (allPages.length > 0) {
// console.log('🔵 第一个页面对象结构:', {
// route: allPages[0].route,
// locale: (allPages[0] as any).locale,
// name: (allPages[0] as any).name,
// kind: allPages[0].kind,
// });
// // 打印前几个页面的详细信息
// allPages.slice(0, 3).forEach((page, idx) => {
// console.log(`🔵 页面 ${idx}:`, {
// route: page.route,
// locale: (page as any).locale,
// name: (page as any).name,
// kind: page.kind,
// });
// });
// }
// }, [allPages]);

// 从文件名或 route 中提取 locale
const extractLocaleFromPage = (page: typeof allPages[0]): string | null => {
// 方法 1: 从 page.locale 属性获取(如果存在)
if ('locale' in page && (page as any).locale) {
return (page as any).locale;
}

// 方法 2: 从 page.name 中提取(例如 "index.zh-CN" -> "zh-CN")
if ('name' in page && (page as any).name) {
const name = (page as any).name as string;
const match = name.match(/\.(en-US|zh-CN)(\.|$)/);
if (match) {
return match[1];
}
}

// 方法 3: 从 route 中提取(例如 "/zh-CN/developers/evm" -> "zh-CN")
if (page.route) {
const routeMatch = page.route.match(/\/(en-US|zh-CN)(\/|$)/);
if (routeMatch) {
return routeMatch[1];
}
}

// 如果没有找到 locale,返回 null(可能是默认语言或无 locale 的页面)
return null;
};

// 新增过滤逻辑(替换原来的日志代码)
// 根据当前 locale 过滤页面,避免显示重复内容
const filteredPages = useMemo(() => {
if (!router.locale || !allPages.length) return allPages;

// 过滤函数:根据 locale 属性过滤页面
const filterByLocale = (pages: typeof allPages, targetLocale: string): typeof allPages => {
return pages
.map((page) => {
if (page.kind === "Folder" && "children" in page) {
// 递归过滤子页面
const filteredChildren = filterByLocale(page.children, targetLocale);

// 如果过滤后没有子页面,不显示这个文件夹
if (filteredChildren.length === 0) return null;

return {
...page,
children: filteredChildren,
};
} else {
// 从页面对象中提取 locale
const pageLocale = extractLocaleFromPage(page);

// 如果页面有明确的 locale 属性
if (pageLocale) {
// 如果匹配目标 locale,保留它
return pageLocale === targetLocale ? page : null;
}

// 如果页面没有 locale 属性:
// - 如果目标是默认语言,保留它(默认语言的页面可能没有 locale 后缀)
// - 如果目标不是默认语言,过滤掉它(没有 locale 后缀的页面应该只在默认语言时显示)
if (targetLocale === router.defaultLocale) {
return page;
}

// 非默认语言时,没有 locale 的页面应该被过滤掉
return null;
}
})
.filter((page): page is typeof allPages[0] => page !== null);
};

return filterByLocale(allPages, router.locale);
}, [allPages, router.locale, router.defaultLocale]);

const { flatDirectories, directoriesByRoute } = useMemo(() => getDirectories(allPages), [allPages]);
// useEffect(() => {
// console.log('🔵 当前 locale:', router.locale);
// console.log('🔵 所有页面数量:', allPages.length);
// console.log('🔵 过滤后页面数量:', filteredPages.length);
// console.log('🔵 过滤后的第一个页面:', filteredPages[0]?.route, (filteredPages[0] as any)?.locale);
// }, [router.locale, allPages.length, filteredPages.length]);
// 使用 filteredPages 而不是 allPages
const { flatDirectories, directoriesByRoute } = useMemo(
() => getDirectories(filteredPages),
[filteredPages]
);

const dispatch = useAppDispatch();

// 使用 filteredPages 而不是 allPages
useEffect(() => {
if (!allPages.length) return;
if (!filteredPages.length) return;

dispatch(setPages(allPages));
}, [allPages]);
dispatch(setPages(filteredPages));
}, [filteredPages, dispatch]);

useEffect(() => {
if (!flatDirectories.length || !directoriesByRoute) return;

dispatch(setDirectories({ flatDirectories, directoriesByRoute }));
}, [flatDirectories, directoriesByRoute]);
};
};
Loading
Loading