index.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. /* 语言切换按钮样式 */
  13. .lang-switch {
  14. position: fixed;
  15. top: 20px;
  16. right: 80px;
  17. z-index: 999;
  18. }
  19. .lang-switch button {
  20. background: #42b983;
  21. color: white;
  22. border: none;
  23. padding: 8px 16px;
  24. border-radius: 4px;
  25. cursor: pointer;
  26. font-size: 14px;
  27. transition: background 0.3s;
  28. }
  29. .lang-switch button:hover {
  30. background: #33a06f;
  31. }
  32. </style>
  33. </head>
  34. <body>
  35. <!-- 语言切换按钮 -->
  36. <div class="lang-switch">
  37. <button id="langBtn" onclick="switchLanguage()">English</button>
  38. </div>
  39. <div id="app"></div>
  40. <script src="//cdn.jsdelivr.net/npm/mermaid@8.0.0-rc.8/dist/mermaid.min.js"></script>
  41. <script>
  42. // 检查语言偏好并设置侧边栏
  43. const preferredLang = localStorage.getItem('preferredLanguage');
  44. const currentHash = window.location.hash;
  45. // 判断当前应该使用哪个语言
  46. let isEnglish = false;
  47. if (preferredLang === 'en' || currentHash.includes('/en/')) {
  48. isEnglish = true;
  49. }
  50. window.$docsify = {
  51. name: 'Hello-Agents',
  52. repo: 'https://github.com/datawhalechina/Hello-Agents',
  53. loadSidebar: true,
  54. auto2top: true,
  55. subMaxLevel: 3,
  56. relativePath: false,
  57. alias: {
  58. // 英文路径映射
  59. '/en/README.md': '/README_EN.md',
  60. '/en/Preface.md': '/Preface.md',
  61. '/en/_sidebar.md': '/_sidebar_en.md',
  62. '/en/chapter(\\d+)/Chapter(.*)': '/chapter$1/Chapter$2',
  63. // 根据语言偏好动态设置默认侧边栏
  64. '/_sidebar.md': isEnglish ? '/_sidebar_en.md' : '/_sidebar.md'
  65. },
  66. pagination: {
  67. previousText: isEnglish ? 'Previous' : '上一章节',
  68. nextText: isEnglish ? 'Next' : '下一章节',
  69. },
  70. count: {
  71. countable: true,
  72. fontsize: '0.9em',
  73. color: 'rgb(90,90,90)',
  74. language: isEnglish ? 'english' : 'chinese'
  75. },
  76. // 多语言配置
  77. fallbackLanguages: ['en'],
  78. nameLink: {
  79. '/en/': '#/en/',
  80. '/': '#/'
  81. }
  82. }
  83. </script>
  84. <!-- Put them above docsify.min.js -->
  85. <script src="//cdn.jsdelivr.net/npm/docsify@latest/lib/docsify.min.js"></script>
  86. <!-- code render-->
  87. <script src="//cdn.jsdelivr.net/npm/prismjs@latest/components/prism-bash.js"></script>
  88. <script src="//cdn.jsdelivr.net/npm/prismjs@latest/components/prism-python.js"></script>
  89. <script src="//cdn.jsdelivr.net/npm/docsify-pagination@latest/dist/docsify-pagination.min.js"></script>
  90. <script src="//cdn.jsdelivr.net/npm/docsify-copy-code"></script>
  91. <script src="https://cdn.jsdelivr.net/npm/katex@latest/dist/katex.min.js"></script>
  92. <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/katex@latest/dist/katex.min.css" />
  93. <script src="https://cdn.jsdelivr.net/npm/marked@3"></script>
  94. <!-- CDN files for docsify-katex -->
  95. <script src="//cdn.jsdelivr.net/npm/docsify-katex@latest/dist/docsify-katex.js"></script>
  96. <!-- 字数统计 -->
  97. <script src="//unpkg.com/docsify-count/dist/countable.js"></script>
  98. <!-- 语言切换脚本 -->
  99. <script>
  100. // 章节文件名映射
  101. const chapterMapping = {
  102. // 中文 -> 英文
  103. 'zh2en': {
  104. 'README.md': 'README_EN.md',
  105. '前言.md': 'Preface.md',
  106. '第一章 初识智能体.md': 'Chapter1-Introduction-to-Agents.md',
  107. '第二章 智能体发展史.md': 'Chapter2-History-of-Agents.md',
  108. '第三章 大语言模型基础.md': 'Chapter3-Fundamentals-of-Large-Language-Models.md',
  109. '第四章 智能体经典范式构建.md': 'Chapter4-Building-Classic-Agent-Paradigms.md',
  110. '第五章 基于低代码平台的智能体搭建.md': 'Chapter5-Building-Agents-with-Low-Code-Platforms.md',
  111. '第六章 框架开发实践.md': 'Chapter6-Framework-Development-Practice.md',
  112. '第七章 构建你的Agent框架.md': 'Chapter7-Building-Your-Agent-Framework.md',
  113. '第八章 记忆与检索.md': 'Chapter8-Memory-and-Retrieval.md',
  114. '第九章 上下文工程.md': 'Chapter9-Context-Engineering.md',
  115. '第十章 智能体通信协议.md': 'Chapter10-Agent-Communication-Protocols.md',
  116. '第十一章 Agentic-RL.md': 'Chapter11-Agentic-RL.md',
  117. '第十二章 智能体性能评估.md': 'Chapter12-Agent-Performance-Evaluation.md',
  118. '第十三章 智能旅行助手.md': 'Chapter13-Intelligent-Travel-Assistant.md',
  119. '第十四章 自动化深度研究智能体.md': 'Chapter14-Automated-Deep-Research-Agent.md',
  120. '第十五章 构建赛博小镇.md': 'Chapter15-Building-Cyber-Town.md',
  121. '第十六章 毕业设计.md': 'Chapter16-Graduation-Project.md'
  122. },
  123. // 英文 -> 中文
  124. 'en2zh': {
  125. 'README_EN.md': 'README.md',
  126. 'Preface.md': '前言.md',
  127. 'Chapter1-Introduction-to-Agents.md': '第一章 初识智能体.md',
  128. 'Chapter2-History-of-Agents.md': '第二章 智能体发展史.md',
  129. 'Chapter3-Fundamentals-of-Large-Language-Models.md': '第三章 大语言模型基础.md',
  130. 'Chapter4-Building-Classic-Agent-Paradigms.md': '第四章 智能体经典范式构建.md',
  131. 'Chapter5-Building-Agents-with-Low-Code-Platforms.md': '第五章 基于低代码平台的智能体搭建.md',
  132. 'Chapter6-Framework-Development-Practice.md': '第六章 框架开发实践.md',
  133. 'Chapter7-Building-Your-Agent-Framework.md': '第七章 构建你的Agent框架.md',
  134. 'Chapter8-Memory-and-Retrieval.md': '第八章 记忆与检索.md',
  135. 'Chapter9-Context-Engineering.md': '第九章 上下文工程.md',
  136. 'Chapter10-Agent-Communication-Protocols.md': '第十章 智能体通信协议.md',
  137. 'Chapter11-Agentic-RL.md': '第十一章 Agentic-RL.md',
  138. 'Chapter12-Agent-Performance-Evaluation.md': '第十二章 智能体性能评估.md',
  139. 'Chapter13-Intelligent-Travel-Assistant.md': '第十三章 智能旅行助手.md',
  140. 'Chapter14-Automated-Deep-Research-Agent.md': '第十四章 自动化深度研究智能体.md',
  141. 'Chapter15-Building-Cyber-Town.md': '第十五章 构建赛博小镇.md',
  142. 'Chapter16-Graduation-Project.md': '第十六章 毕业设计.md'
  143. }
  144. };
  145. function switchLanguage() {
  146. const currentHash = window.location.hash;
  147. const langBtn = document.getElementById('langBtn');
  148. // 检测当前语言
  149. if (currentHash.includes('/en/')) {
  150. // 从英文切换到中文
  151. localStorage.setItem('preferredLanguage', 'zh');
  152. let newHash = currentHash.replace('#/', '').replace('en/', '');
  153. // 提取文件名
  154. const parts = newHash.split('/');
  155. const filename = parts[parts.length - 1];
  156. // 查找对应的中文文件名
  157. if (chapterMapping.en2zh[filename]) {
  158. parts[parts.length - 1] = chapterMapping.en2zh[filename];
  159. newHash = '#/' + parts.join('/');
  160. } else {
  161. newHash = '#/';
  162. }
  163. window.location.hash = newHash;
  164. langBtn.textContent = 'English';
  165. window.$docsify.pagination.previousText = '上一章节';
  166. window.$docsify.pagination.nextText = '下一章节';
  167. } else {
  168. // 从中文切换到英文
  169. localStorage.setItem('preferredLanguage', 'en');
  170. let path = currentHash.replace('#/', '');
  171. if (path === '' || path === '/') {
  172. // 首页
  173. window.location.hash = '#/en/README_EN.md';
  174. } else {
  175. // 提取文件名
  176. const parts = path.split('/');
  177. const filename = parts[parts.length - 1];
  178. // 查找对应的英文文件名
  179. if (chapterMapping.zh2en[filename]) {
  180. parts[parts.length - 1] = chapterMapping.zh2en[filename];
  181. window.location.hash = '#/en/' + parts.join('/');
  182. } else {
  183. window.location.hash = '#/en/README_EN.md';
  184. }
  185. }
  186. langBtn.textContent = '中文';
  187. window.$docsify.pagination.previousText = 'Previous';
  188. window.$docsify.pagination.nextText = 'Next';
  189. }
  190. // 重新加载页面以应用新的 sidebar
  191. window.location.reload();
  192. }
  193. // 页面加载时设置按钮文本和检查语言偏好
  194. window.addEventListener('load', function() {
  195. const currentHash = window.location.hash;
  196. const langBtn = document.getElementById('langBtn');
  197. const preferredLang = localStorage.getItem('preferredLanguage');
  198. // 如果用户有语言偏好,且当前 URL 不匹配偏好,则自动切换
  199. if (preferredLang === 'en' && !currentHash.includes('/en/')) {
  200. // 用户偏好英文,但当前是中文页面
  201. let path = currentHash.replace('#/', '');
  202. if (path === '' || path === '/') {
  203. window.location.hash = '#/en/README_EN.md';
  204. } else {
  205. const parts = path.split('/');
  206. const filename = parts[parts.length - 1];
  207. if (chapterMapping.zh2en[filename]) {
  208. parts[parts.length - 1] = chapterMapping.zh2en[filename];
  209. window.location.hash = '#/en/' + parts.join('/');
  210. }
  211. }
  212. } else if (preferredLang === 'zh' && currentHash.includes('/en/')) {
  213. // 用户偏好中文,但当前是英文页面
  214. let newHash = currentHash.replace('#/', '').replace('en/', '');
  215. const parts = newHash.split('/');
  216. const filename = parts[parts.length - 1];
  217. if (chapterMapping.en2zh[filename]) {
  218. parts[parts.length - 1] = chapterMapping.en2zh[filename];
  219. window.location.hash = '#/' + parts.join('/');
  220. }
  221. }
  222. // 设置按钮文本
  223. if (currentHash.includes('/en/') || preferredLang === 'en') {
  224. langBtn.textContent = '中文';
  225. } else {
  226. langBtn.textContent = 'English';
  227. }
  228. });
  229. </script>
  230. </body>
  231. </html>