index.html 11 KB

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