1
0

index.html 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Hello-Agents</title>
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  7. <meta name="description" content="Description">
  8. <meta name="viewport"
  9. content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  10. <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify@latest/lib/themes/vue.css">
  11. <style>
  12. /* --- 1. 原有样式 (保留) --- */
  13. /* 语言切换按钮样式 */
  14. .lang-switch {
  15. position: fixed;
  16. top: 20px;
  17. right: 80px;
  18. z-index: 999;
  19. }
  20. .lang-switch button {
  21. background: #42b983;
  22. color: white;
  23. border: none;
  24. padding: 8px 16px;
  25. border-radius: 4px;
  26. cursor: pointer;
  27. font-size: 14px;
  28. transition: background 0.3s;
  29. }
  30. .lang-switch button:hover {
  31. background: #33a06f;
  32. }
  33. /* Giscus 评论区样式 */
  34. .giscus-container {
  35. margin-top: 60px;
  36. padding-top: 40px;
  37. border-top: 1px solid #eee;
  38. }
  39. /* 可折叠评论区标题 */
  40. .giscus-toggle {
  41. display: flex;
  42. align-items: center;
  43. justify-content: space-between;
  44. cursor: pointer;
  45. padding: 15px 20px;
  46. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  47. border-radius: 8px;
  48. margin-bottom: 20px;
  49. transition: all 0.3s ease;
  50. box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
  51. }
  52. .giscus-toggle:hover {
  53. transform: translateY(-2px);
  54. box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
  55. }
  56. .giscus-toggle-title {
  57. font-size: 1.3em;
  58. font-weight: 600;
  59. color: white;
  60. margin: 0;
  61. display: flex;
  62. align-items: center;
  63. gap: 10px;
  64. }
  65. .giscus-toggle-icon {
  66. font-size: 1.2em;
  67. transition: transform 0.3s ease;
  68. color: white;
  69. }
  70. .giscus-toggle-icon.expanded {
  71. transform: rotate(180deg);
  72. }
  73. .giscus-content {
  74. max-height: 0;
  75. overflow: hidden;
  76. transition: max-height 0.4s ease-out, opacity 0.3s ease;
  77. opacity: 0;
  78. }
  79. .giscus-content.expanded {
  80. max-height: 2000px;
  81. opacity: 1;
  82. transition: max-height 0.5s ease-in, opacity 0.4s ease;
  83. }
  84. .giscus-hint {
  85. font-size: 0.9em;
  86. color: rgba(255, 255, 255, 0.9);
  87. margin: 0;
  88. }
  89. /* --- 2. 新增:暗黑模式样式 (Dark Mode Styles) --- */
  90. :root {
  91. --dark-bg: #1a1a1a;
  92. --dark-text: #c4c4c4;
  93. --dark-sidebar: #141414;
  94. --dark-code-bg: #2b2b2b;
  95. --dark-border: #333;
  96. --theme-color: #42b983;
  97. }
  98. /* 基础反色 */
  99. body.dark-mode {
  100. background-color: var(--dark-bg);
  101. color: var(--dark-text);
  102. }
  103. /* 侧边栏适配 */
  104. body.dark-mode .sidebar {
  105. background-color: var(--dark-sidebar);
  106. border-right: 1px solid var(--dark-border);
  107. color: var(--dark-text);
  108. }
  109. body.dark-mode .sidebar-nav li a {
  110. color: #999;
  111. }
  112. body.dark-mode .sidebar-nav li.active > a {
  113. color: var(--theme-color);
  114. border-right: 2px solid var(--theme-color);
  115. }
  116. /* 代码块适配 */
  117. body.dark-mode pre {
  118. background-color: var(--dark-code-bg) !important;
  119. }
  120. body.dark-mode code {
  121. background-color: var(--dark-code-bg) !important;
  122. color: #e0e0e0 !important;
  123. }
  124. body.dark-mode .markdown-section code {
  125. color: #f08d49;
  126. background-color: rgba(255,255,255,0.1);
  127. }
  128. /* 标题和引用适配 */
  129. body.dark-mode h1, body.dark-mode h2, body.dark-mode h3, body.dark-mode h4 {
  130. color: #e0e0e0;
  131. }
  132. body.dark-mode blockquote {
  133. color: #999;
  134. background: rgba(255,255,255,0.05);
  135. border-left-color: var(--theme-color);
  136. }
  137. /* 表格适配 */
  138. body.dark-mode .markdown-section tr:nth-child(2n) {
  139. background-color: rgba(255,255,255,0.03);
  140. }
  141. body.dark-mode .markdown-section td,
  142. body.dark-mode .markdown-section th {
  143. border-color: var(--dark-border);
  144. }
  145. /* Mermaid 图表适配 (颜色反转) */
  146. body.dark-mode .mermaid {
  147. filter: invert(1) hue-rotate(180deg);
  148. }
  149. /* Giscus 容器边框适配 */
  150. body.dark-mode .giscus-container {
  151. border-top: 1px solid var(--dark-border);
  152. }
  153. /* --- 3. 新增:侧边栏开关按钮样式 --- */
  154. .sidebar-toggle-btn {
  155. cursor: pointer;
  156. display: block;
  157. text-align: center;
  158. padding: 10px 0;
  159. margin: 0 15px 10px 15px;
  160. font-weight: bold;
  161. font-size: 14px;
  162. border-radius: 4px;
  163. background-color: rgba(0,0,0,0.05);
  164. color: #505d6b;
  165. border: 1px solid rgba(0,0,0,0.05);
  166. transition: all 0.3s;
  167. }
  168. body.dark-mode .sidebar-toggle-btn {
  169. background-color: rgba(255,255,255,0.1);
  170. color: #ccc;
  171. border: 1px solid #444;
  172. }
  173. .sidebar-toggle-btn:hover {
  174. background-color: var(--theme-color);
  175. color: white;
  176. }
  177. </style>
  178. </head>
  179. <body>
  180. <!-- 语言切换按钮 -->
  181. <div class="lang-switch">
  182. <button id="langBtn" onclick="switchLanguage()">English</button>
  183. </div>
  184. <div id="app"></div>
  185. <script src="//cdn.jsdelivr.net/npm/mermaid@8.0.0-rc.8/dist/mermaid.min.js"></script>
  186. <script>
  187. window.$docsify = {
  188. name: 'Hello-Agents',
  189. repo: 'https://github.com/datawhalechina/Hello-Agents',
  190. loadSidebar: true,
  191. auto2top: true,
  192. subMaxLevel: 3,
  193. relativePath: false,
  194. alias: {
  195. // 英文路径映射
  196. '/en/README.md': '/README_EN.md',
  197. '/en/_sidebar.md': '/_sidebar_en.md',
  198. '/en/.*/_sidebar.md': '/_sidebar_en.md',
  199. '/en/chapter(\\d+)/Chapter(.*)': '/chapter$1/Chapter$2',
  200. // 默认中文侧边栏
  201. '/_sidebar.md': '/_sidebar.md',
  202. '/.*/_sidebar.md': '/_sidebar.md'
  203. },
  204. pagination: {
  205. previousText: '上一章节',
  206. nextText: '下一章节',
  207. },
  208. count: {
  209. countable: true,
  210. fontsize: '0.9em',
  211. color: 'rgb(90,90,90)',
  212. language: 'chinese'
  213. },
  214. // 多语言配置
  215. fallbackLanguages: ['en'],
  216. nameLink: {
  217. '/en/': '#/en/',
  218. '/': '#/'
  219. },
  220. // 使用钩子动态处理侧边栏
  221. plugins: [
  222. // --- 新增:暗黑模式开关插件 ---
  223. function(hook, vm) {
  224. hook.doneEach(function() {
  225. const sidebar = document.querySelector('.sidebar-nav');
  226. // 防止重复添加
  227. if (!sidebar || document.querySelector('.sidebar-toggle-btn')) return;
  228. const btn = document.createElement('div');
  229. btn.className = 'sidebar-toggle-btn';
  230. // 初始化状态
  231. const savedTheme = localStorage.getItem('theme-mode');
  232. if (savedTheme === 'dark') {
  233. document.body.classList.add('dark-mode');
  234. btn.textContent = '🌙 Switch to Light';
  235. } else {
  236. btn.textContent = '☀️ Switch to Dark';
  237. }
  238. // 核心:点击事件
  239. btn.onclick = function() {
  240. // 1. 切换类名
  241. document.body.classList.toggle('dark-mode');
  242. const isDark = document.body.classList.contains('dark-mode');
  243. // 2. 保存状态
  244. localStorage.setItem('theme-mode', isDark ? 'dark' : 'light');
  245. // 3. 更新按钮文字
  246. btn.textContent = isDark ? '🌙 Switch to Light' : '☀️ Switch to Dark';
  247. // 4. 关键:通知 Giscus 切换主题 (无需刷新)
  248. const iframe = document.querySelector('iframe.giscus-frame');
  249. if (iframe) {
  250. iframe.contentWindow.postMessage({
  251. giscus: {
  252. setConfig: {
  253. theme: isDark ? 'dark' : 'light'
  254. }
  255. }
  256. }, 'https://giscus.app');
  257. }
  258. };
  259. // 插入到侧边栏最顶部
  260. sidebar.insertBefore(btn, sidebar.firstChild);
  261. });
  262. },
  263. // --- 原有逻辑:语言偏好处理 ---
  264. function(hook, vm) {
  265. // 在每次路由变化时检查语言偏好
  266. hook.beforeEach(function(content) {
  267. const preferredLang = localStorage.getItem('preferredLanguage');
  268. const currentPath = vm.route.path;
  269. // 根据当前路径或语言偏好更新分页文本
  270. if (currentPath.includes('/en/') || preferredLang === 'en') {
  271. window.$docsify.pagination.previousText = 'Previous';
  272. window.$docsify.pagination.nextText = 'Next';
  273. } else {
  274. window.$docsify.pagination.previousText = '上一章节';
  275. window.$docsify.pagination.nextText = '下一章节';
  276. }
  277. return content;
  278. });
  279. // 在页面渲染后添加 Giscus 评论区
  280. hook.doneEach(function() {
  281. // 检查是否是章节页面(排除首页和前言)
  282. const currentPath = vm.route.path;
  283. const isChapterPage = currentPath.includes('chapter') ||
  284. currentPath.includes('Chapter') ||
  285. currentPath.includes('第') && currentPath.includes('章');
  286. if (!isChapterPage) {
  287. return; // 非章节页面不显示评论区
  288. }
  289. // 移除旧的评论区
  290. const oldGiscus = document.querySelector('.giscus-container');
  291. if (oldGiscus) {
  292. oldGiscus.remove();
  293. }
  294. // 创建评论区容器
  295. const giscusContainer = document.createElement('div');
  296. giscusContainer.className = 'giscus-container';
  297. // 获取语言设置
  298. const preferredLang = localStorage.getItem('preferredLanguage');
  299. const isEnglish = currentPath.includes('/en/') || preferredLang === 'en';
  300. // --- 获取当前主题状态 (新增逻辑) ---
  301. // 这里是为了在创建 Giscus 时就设置正确的初始主题
  302. const isDarkMode = document.body.classList.contains('dark-mode');
  303. // 创建可折叠的标题栏
  304. const toggleButton = document.createElement('div');
  305. toggleButton.className = 'giscus-toggle';
  306. const titleDiv = document.createElement('div');
  307. titleDiv.className = 'giscus-toggle-title';
  308. titleDiv.innerHTML = isEnglish
  309. ? '💬 Discussion & Questions'
  310. : '💬 讨论与提问';
  311. const hintText = document.createElement('p');
  312. hintText.className = 'giscus-hint';
  313. hintText.textContent = isEnglish
  314. ? 'Click to expand/collapse'
  315. : '点击展开/收起';
  316. const iconSpan = document.createElement('span');
  317. iconSpan.className = 'giscus-toggle-icon';
  318. iconSpan.textContent = '▼';
  319. const titleWrapper = document.createElement('div');
  320. titleWrapper.appendChild(titleDiv);
  321. titleWrapper.appendChild(hintText);
  322. toggleButton.appendChild(titleWrapper);
  323. toggleButton.appendChild(iconSpan);
  324. // 创建评论内容容器
  325. const contentDiv = document.createElement('div');
  326. contentDiv.className = 'giscus-content';
  327. // 创建 Giscus 脚本
  328. const giscusScript = document.createElement('script');
  329. giscusScript.src = 'https://giscus.app/client.js';
  330. giscusScript.setAttribute('data-repo', 'datawhalechina/hello-agents');
  331. giscusScript.setAttribute('data-repo-id', 'R_kgDOPrUECg');
  332. giscusScript.setAttribute('data-category', '💬 Exercises & Q&A');
  333. giscusScript.setAttribute('data-category-id', 'DIC_kwDOPrUECs4Cxfyu');
  334. giscusScript.setAttribute('data-mapping', 'pathname');
  335. giscusScript.setAttribute('data-strict', '0');
  336. giscusScript.setAttribute('data-reactions-enabled', '1');
  337. giscusScript.setAttribute('data-emit-metadata', '0');
  338. giscusScript.setAttribute('data-input-position', 'top');
  339. // --- 修改:强制跟随当前 dark-mode 状态 ---
  340. // 如果当前 body 有 dark-mode 类,则初始化为 'dark',否则 'light'
  341. giscusScript.setAttribute('data-theme', isDarkMode ? 'dark' : 'light');
  342. giscusScript.setAttribute('data-lang', isEnglish ? 'en' : 'zh-CN');
  343. giscusScript.setAttribute('data-loading', 'lazy');
  344. giscusScript.crossOrigin = 'anonymous';
  345. giscusScript.async = true;
  346. contentDiv.appendChild(giscusScript);
  347. // 组装评论区
  348. giscusContainer.appendChild(toggleButton);
  349. giscusContainer.appendChild(contentDiv);
  350. // 添加折叠/展开功能
  351. let isExpanded = false;
  352. toggleButton.addEventListener('click', function() {
  353. isExpanded = !isExpanded;
  354. if (isExpanded) {
  355. contentDiv.classList.add('expanded');
  356. iconSpan.classList.add('expanded');
  357. } else {
  358. contentDiv.classList.remove('expanded');
  359. iconSpan.classList.remove('expanded');
  360. }
  361. });
  362. // 将评论区添加到内容区域
  363. const article = document.querySelector('article.markdown-section');
  364. if (article) {
  365. article.appendChild(giscusContainer);
  366. }
  367. });
  368. }
  369. ]
  370. }
  371. </script>
  372. <!-- Put them above docsify.min.js -->
  373. <script src="//cdn.jsdelivr.net/npm/docsify@latest/lib/docsify.min.js"></script>
  374. <!-- code render-->
  375. <script src="//cdn.jsdelivr.net/npm/prismjs@latest/components/prism-bash.js"></script>
  376. <script src="//cdn.jsdelivr.net/npm/prismjs@latest/components/prism-python.js"></script>
  377. <script src="//cdn.jsdelivr.net/npm/docsify-pagination@latest/dist/docsify-pagination.min.js"></script>
  378. <script src="//cdn.jsdelivr.net/npm/docsify-copy-code"></script>
  379. <!-- 新增:图片放大插件 (官方) -->
  380. <script src="//cdn.jsdelivr.net/npm/docsify/lib/plugins/zoom-image.min.js"></script>
  381. <script src="https://cdn.jsdelivr.net/npm/katex@latest/dist/katex.min.js"></script>
  382. <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/katex@latest/dist/katex.min.css" />
  383. <script src="https://cdn.jsdelivr.net/npm/marked@3"></script>
  384. <!-- CDN files for docsify-katex -->
  385. <script src="//cdn.jsdelivr.net/npm/docsify-katex@latest/dist/docsify-katex.js"></script>
  386. <!-- 字数统计 -->
  387. <script src="//unpkg.com/docsify-count/dist/countable.js"></script>
  388. <!-- 语言切换脚本 (保留原样) -->
  389. <script>
  390. // 章节文件名映射
  391. const chapterMapping = {
  392. // 中文 -> 英文
  393. 'zh2en': {
  394. 'README.md': 'README_EN.md',
  395. '前言.md': 'Preface.md',
  396. '第一章 初识智能体.md': 'Chapter1-Introduction-to-Agents.md',
  397. '第二章 智能体发展史.md': 'Chapter2-History-of-Agents.md',
  398. '第三章 大语言模型基础.md': 'Chapter3-Fundamentals-of-Large-Language-Models.md',
  399. '第四章 智能体经典范式构建.md': 'Chapter4-Building-Classic-Agent-Paradigms.md',
  400. '第五章 基于低代码平台的智能体搭建.md': 'Chapter5-Building-Agents-with-Low-Code-Platforms.md',
  401. '第六章 框架开发实践.md': 'Chapter6-Framework-Development-Practice.md',
  402. '第七章 构建你的Agent框架.md': 'Chapter7-Building-Your-Agent-Framework.md',
  403. '第八章 记忆与检索.md': 'Chapter8-Memory-and-Retrieval.md',
  404. '第九章 上下文工程.md': 'Chapter9-Context-Engineering.md',
  405. '第十章 智能体通信协议.md': 'Chapter10-Agent-Communication-Protocols.md',
  406. '第十一章 Agentic-RL.md': 'Chapter11-Agentic-RL.md',
  407. '第十二章 智能体性能评估.md': 'Chapter12-Agent-Performance-Evaluation.md',
  408. '第十三章 智能旅行助手.md': 'Chapter13-Intelligent-Travel-Assistant.md',
  409. '第十四章 自动化深度研究智能体.md': 'Chapter14-Automated-Deep-Research-Agent.md',
  410. '第十五章 构建赛博小镇.md': 'Chapter15-Building-Cyber-Town.md',
  411. '第十六章 毕业设计.md': 'Chapter16-Graduation-Project.md'
  412. },
  413. // 英文 -> 中文
  414. 'en2zh': {
  415. 'README_EN.md': 'README.md',
  416. 'Preface.md': '前言.md',
  417. 'Chapter1-Introduction-to-Agents.md': '第一章 初识智能体.md',
  418. 'Chapter2-History-of-Agents.md': '第二章 智能体发展史.md',
  419. 'Chapter3-Fundamentals-of-Large-Language-Models.md': '第三章 大语言模型基础.md',
  420. 'Chapter4-Building-Classic-Agent-Paradigms.md': '第四章 智能体经典范式构建.md',
  421. 'Chapter5-Building-Agents-with-Low-Code-Platforms.md': '第五章 基于低代码平台的智能体搭建.md',
  422. 'Chapter6-Framework-Development-Practice.md': '第六章 框架开发实践.md',
  423. 'Chapter7-Building-Your-Agent-Framework.md': '第七章 构建你的Agent框架.md',
  424. 'Chapter8-Memory-and-Retrieval.md': '第八章 记忆与检索.md',
  425. 'Chapter9-Context-Engineering.md': '第九章 上下文工程.md',
  426. 'Chapter10-Agent-Communication-Protocols.md': '第十章 智能体通信协议.md',
  427. 'Chapter11-Agentic-RL.md': '第十一章 Agentic-RL.md',
  428. 'Chapter12-Agent-Performance-Evaluation.md': '第十二章 智能体性能评估.md',
  429. 'Chapter13-Intelligent-Travel-Assistant.md': '第十三章 智能旅行助手.md',
  430. 'Chapter14-Automated-Deep-Research-Agent.md': '第十四章 自动化深度研究智能体.md',
  431. 'Chapter15-Building-Cyber-Town.md': '第十五章 构建赛博小镇.md',
  432. 'Chapter16-Graduation-Project.md': '第十六章 毕业设计.md'
  433. }
  434. };
  435. function switchLanguage() {
  436. const currentHash = window.location.hash;
  437. const langBtn = document.getElementById('langBtn');
  438. // 检测当前语言
  439. if (currentHash.includes('/en/')) {
  440. // 从英文切换到中文
  441. localStorage.setItem('preferredLanguage', 'zh');
  442. let newHash = currentHash.replace('#/', '').replace('en/', '');
  443. // 提取文件名
  444. const parts = newHash.split('/');
  445. const filename = parts[parts.length - 1];
  446. // 查找对应的中文文件名
  447. if (chapterMapping.en2zh[filename]) {
  448. parts[parts.length - 1] = chapterMapping.en2zh[filename];
  449. newHash = '#/' + parts.join('/');
  450. } else {
  451. newHash = '#/';
  452. }
  453. window.location.hash = newHash;
  454. langBtn.textContent = 'English';
  455. window.$docsify.pagination.previousText = '上一章节';
  456. window.$docsify.pagination.nextText = '下一章节';
  457. } else {
  458. // 从中文切换到英文
  459. localStorage.setItem('preferredLanguage', 'en');
  460. let path = currentHash.replace('#/', '');
  461. if (path === '' || path === '/') {
  462. // 首页
  463. window.location.hash = '#/en/README_EN.md';
  464. } else {
  465. // 提取文件名
  466. const parts = path.split('/');
  467. const filename = parts[parts.length - 1];
  468. // 查找对应的英文文件名
  469. if (chapterMapping.zh2en[filename]) {
  470. parts[parts.length - 1] = chapterMapping.zh2en[filename];
  471. window.location.hash = '#/en/' + parts.join('/');
  472. } else {
  473. window.location.hash = '#/en/README_EN.md';
  474. }
  475. }
  476. langBtn.textContent = '中文';
  477. window.$docsify.pagination.previousText = 'Previous';
  478. window.$docsify.pagination.nextText = 'Next';
  479. }
  480. // 重新加载页面以应用新的 sidebar
  481. window.location.reload();
  482. }
  483. // 页面加载时设置按钮文本和检查语言偏好
  484. window.addEventListener('load', function() {
  485. const currentHash = window.location.hash;
  486. const langBtn = document.getElementById('langBtn');
  487. const preferredLang = localStorage.getItem('preferredLanguage');
  488. // 只有在用户明确设置了语言偏好后,才自动切换
  489. // 首次访问(没有偏好设置)时,默认显示中文版
  490. if (preferredLang) {
  491. // 如果用户有语言偏好,且当前 URL 不匹配偏好,则自动切换
  492. if (preferredLang === 'en' && !currentHash.includes('/en/')) {
  493. // 用户偏好英文,但当前是中文页面
  494. let path = currentHash.replace('#/', '');
  495. if (path === '' || path === '/') {
  496. window.location.hash = '#/en/README_EN.md';
  497. } else {
  498. const parts = path.split('/');
  499. const filename = parts[parts.length - 1];
  500. if (chapterMapping.zh2en[filename]) {
  501. parts[parts.length - 1] = chapterMapping.zh2en[filename];
  502. window.location.hash = '#/en/' + parts.join('/');
  503. }
  504. }
  505. } else if (preferredLang === 'zh' && currentHash.includes('/en/')) {
  506. // 用户偏好中文,但当前是英文页面
  507. let newHash = currentHash.replace('#/', '').replace('en/', '');
  508. const parts = newHash.split('/');
  509. const filename = parts[parts.length - 1];
  510. if (chapterMapping.en2zh[filename]) {
  511. parts[parts.length - 1] = chapterMapping.en2zh[filename];
  512. window.location.hash = '#/' + parts.join('/');
  513. }
  514. }
  515. }
  516. // 设置按钮文本
  517. if (currentHash.includes('/en/')) {
  518. langBtn.textContent = '中文';
  519. } else {
  520. langBtn.textContent = 'English';
  521. }
  522. });
  523. </script>
  524. </body>
  525. </html>