index.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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. /* Giscus 评论区样式 */
  33. .giscus-container {
  34. margin-top: 60px;
  35. padding-top: 40px;
  36. border-top: 1px solid #eee;
  37. }
  38. /* 可折叠评论区标题 */
  39. .giscus-toggle {
  40. display: flex;
  41. align-items: center;
  42. justify-content: space-between;
  43. cursor: pointer;
  44. padding: 15px 20px;
  45. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  46. border-radius: 8px;
  47. margin-bottom: 20px;
  48. transition: all 0.3s ease;
  49. box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
  50. }
  51. .giscus-toggle:hover {
  52. transform: translateY(-2px);
  53. box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
  54. }
  55. .giscus-toggle-title {
  56. font-size: 1.3em;
  57. font-weight: 600;
  58. color: white;
  59. margin: 0;
  60. display: flex;
  61. align-items: center;
  62. gap: 10px;
  63. }
  64. .giscus-toggle-icon {
  65. font-size: 1.2em;
  66. transition: transform 0.3s ease;
  67. color: white;
  68. }
  69. .giscus-toggle-icon.expanded {
  70. transform: rotate(180deg);
  71. }
  72. .giscus-content {
  73. max-height: 0;
  74. overflow: hidden;
  75. transition: max-height 0.4s ease-out, opacity 0.3s ease;
  76. opacity: 0;
  77. }
  78. .giscus-content.expanded {
  79. max-height: 2000px;
  80. opacity: 1;
  81. transition: max-height 0.5s ease-in, opacity 0.4s ease;
  82. }
  83. .giscus-hint {
  84. font-size: 0.9em;
  85. color: rgba(255, 255, 255, 0.9);
  86. margin: 0;
  87. }
  88. </style>
  89. </head>
  90. <body>
  91. <!-- 语言切换按钮 -->
  92. <div class="lang-switch">
  93. <button id="langBtn" onclick="switchLanguage()">English</button>
  94. </div>
  95. <div id="app"></div>
  96. <script src="//cdn.jsdelivr.net/npm/mermaid@8.0.0-rc.8/dist/mermaid.min.js"></script>
  97. <script>
  98. window.$docsify = {
  99. name: 'Hello-Agents',
  100. repo: 'https://github.com/datawhalechina/Hello-Agents',
  101. loadSidebar: true,
  102. auto2top: true,
  103. subMaxLevel: 3,
  104. relativePath: false,
  105. alias: {
  106. // 英文路径映射
  107. '/en/README.md': '/README_EN.md',
  108. '/en/Preface.md': '/Preface.md',
  109. '/en/_sidebar.md': '/_sidebar_en.md',
  110. '/en/chapter(\\d+)/Chapter(.*)': '/chapter$1/Chapter$2',
  111. // 默认中文侧边栏
  112. '/_sidebar.md': '/_sidebar.md'
  113. },
  114. pagination: {
  115. previousText: '上一章节',
  116. nextText: '下一章节',
  117. },
  118. count: {
  119. countable: true,
  120. fontsize: '0.9em',
  121. color: 'rgb(90,90,90)',
  122. language: 'chinese'
  123. },
  124. // 多语言配置
  125. fallbackLanguages: ['en'],
  126. nameLink: {
  127. '/en/': '#/en/',
  128. '/': '#/'
  129. },
  130. // 使用钩子动态处理侧边栏
  131. plugins: [
  132. function(hook, vm) {
  133. // 在每次路由变化时检查语言偏好
  134. hook.beforeEach(function(content) {
  135. const preferredLang = localStorage.getItem('preferredLanguage');
  136. const currentPath = vm.route.path;
  137. // 根据当前路径或语言偏好更新分页文本
  138. if (currentPath.includes('/en/') || preferredLang === 'en') {
  139. window.$docsify.pagination.previousText = 'Previous';
  140. window.$docsify.pagination.nextText = 'Next';
  141. } else {
  142. window.$docsify.pagination.previousText = '上一章节';
  143. window.$docsify.pagination.nextText = '下一章节';
  144. }
  145. return content;
  146. });
  147. // 在页面渲染后添加 Giscus 评论区
  148. hook.doneEach(function() {
  149. // 检查是否是章节页面(排除首页和前言)
  150. const currentPath = vm.route.path;
  151. const isChapterPage = currentPath.includes('chapter') ||
  152. currentPath.includes('Chapter') ||
  153. currentPath.includes('第') && currentPath.includes('章');
  154. if (!isChapterPage) {
  155. return; // 非章节页面不显示评论区
  156. }
  157. // 移除旧的评论区
  158. const oldGiscus = document.querySelector('.giscus-container');
  159. if (oldGiscus) {
  160. oldGiscus.remove();
  161. }
  162. // 创建评论区容器
  163. const giscusContainer = document.createElement('div');
  164. giscusContainer.className = 'giscus-container';
  165. // 获取语言设置
  166. const preferredLang = localStorage.getItem('preferredLanguage');
  167. const isEnglish = currentPath.includes('/en/') || preferredLang === 'en';
  168. // 创建可折叠的标题栏
  169. const toggleButton = document.createElement('div');
  170. toggleButton.className = 'giscus-toggle';
  171. const titleDiv = document.createElement('div');
  172. titleDiv.className = 'giscus-toggle-title';
  173. titleDiv.innerHTML = isEnglish
  174. ? '💬 Discussion & Questions'
  175. : '💬 讨论与提问';
  176. const hintText = document.createElement('p');
  177. hintText.className = 'giscus-hint';
  178. hintText.textContent = isEnglish
  179. ? 'Click to expand/collapse'
  180. : '点击展开/收起';
  181. const iconSpan = document.createElement('span');
  182. iconSpan.className = 'giscus-toggle-icon';
  183. iconSpan.textContent = '▼';
  184. const titleWrapper = document.createElement('div');
  185. titleWrapper.appendChild(titleDiv);
  186. titleWrapper.appendChild(hintText);
  187. toggleButton.appendChild(titleWrapper);
  188. toggleButton.appendChild(iconSpan);
  189. // 创建评论内容容器
  190. const contentDiv = document.createElement('div');
  191. contentDiv.className = 'giscus-content';
  192. // 创建 Giscus 脚本
  193. const giscusScript = document.createElement('script');
  194. giscusScript.src = 'https://giscus.app/client.js';
  195. giscusScript.setAttribute('data-repo', 'datawhalechina/hello-agents');
  196. giscusScript.setAttribute('data-repo-id', 'R_kgDOPrUECg');
  197. giscusScript.setAttribute('data-category', '💬 Exercises & Q&A');
  198. giscusScript.setAttribute('data-category-id', 'DIC_kwDOPrUECs4Cxfyu');
  199. giscusScript.setAttribute('data-mapping', 'pathname');
  200. giscusScript.setAttribute('data-strict', '0');
  201. giscusScript.setAttribute('data-reactions-enabled', '1');
  202. giscusScript.setAttribute('data-emit-metadata', '0');
  203. giscusScript.setAttribute('data-input-position', 'top');
  204. giscusScript.setAttribute('data-theme', 'preferred_color_scheme');
  205. giscusScript.setAttribute('data-lang', isEnglish ? 'en' : 'zh-CN');
  206. giscusScript.setAttribute('data-loading', 'lazy');
  207. giscusScript.crossOrigin = 'anonymous';
  208. giscusScript.async = true;
  209. contentDiv.appendChild(giscusScript);
  210. // 组装评论区
  211. giscusContainer.appendChild(toggleButton);
  212. giscusContainer.appendChild(contentDiv);
  213. // 添加折叠/展开功能
  214. let isExpanded = false;
  215. toggleButton.addEventListener('click', function() {
  216. isExpanded = !isExpanded;
  217. if (isExpanded) {
  218. contentDiv.classList.add('expanded');
  219. iconSpan.classList.add('expanded');
  220. } else {
  221. contentDiv.classList.remove('expanded');
  222. iconSpan.classList.remove('expanded');
  223. }
  224. });
  225. // 将评论区添加到内容区域
  226. const article = document.querySelector('article.markdown-section');
  227. if (article) {
  228. article.appendChild(giscusContainer);
  229. }
  230. });
  231. }
  232. ]
  233. }
  234. </script>
  235. <!-- Put them above docsify.min.js -->
  236. <script src="//cdn.jsdelivr.net/npm/docsify@latest/lib/docsify.min.js"></script>
  237. <!-- code render-->
  238. <script src="//cdn.jsdelivr.net/npm/prismjs@latest/components/prism-bash.js"></script>
  239. <script src="//cdn.jsdelivr.net/npm/prismjs@latest/components/prism-python.js"></script>
  240. <script src="//cdn.jsdelivr.net/npm/docsify-pagination@latest/dist/docsify-pagination.min.js"></script>
  241. <script src="//cdn.jsdelivr.net/npm/docsify-copy-code"></script>
  242. <script src="https://cdn.jsdelivr.net/npm/katex@latest/dist/katex.min.js"></script>
  243. <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/katex@latest/dist/katex.min.css" />
  244. <script src="https://cdn.jsdelivr.net/npm/marked@3"></script>
  245. <!-- CDN files for docsify-katex -->
  246. <script src="//cdn.jsdelivr.net/npm/docsify-katex@latest/dist/docsify-katex.js"></script>
  247. <!-- 字数统计 -->
  248. <script src="//unpkg.com/docsify-count/dist/countable.js"></script>
  249. <!-- 语言切换脚本 -->
  250. <script>
  251. // 章节文件名映射
  252. const chapterMapping = {
  253. // 中文 -> 英文
  254. 'zh2en': {
  255. 'README.md': 'README_EN.md',
  256. '前言.md': 'Preface.md',
  257. '第一章 初识智能体.md': 'Chapter1-Introduction-to-Agents.md',
  258. '第二章 智能体发展史.md': 'Chapter2-History-of-Agents.md',
  259. '第三章 大语言模型基础.md': 'Chapter3-Fundamentals-of-Large-Language-Models.md',
  260. '第四章 智能体经典范式构建.md': 'Chapter4-Building-Classic-Agent-Paradigms.md',
  261. '第五章 基于低代码平台的智能体搭建.md': 'Chapter5-Building-Agents-with-Low-Code-Platforms.md',
  262. '第六章 框架开发实践.md': 'Chapter6-Framework-Development-Practice.md',
  263. '第七章 构建你的Agent框架.md': 'Chapter7-Building-Your-Agent-Framework.md',
  264. '第八章 记忆与检索.md': 'Chapter8-Memory-and-Retrieval.md',
  265. '第九章 上下文工程.md': 'Chapter9-Context-Engineering.md',
  266. '第十章 智能体通信协议.md': 'Chapter10-Agent-Communication-Protocols.md',
  267. '第十一章 Agentic-RL.md': 'Chapter11-Agentic-RL.md',
  268. '第十二章 智能体性能评估.md': 'Chapter12-Agent-Performance-Evaluation.md',
  269. '第十三章 智能旅行助手.md': 'Chapter13-Intelligent-Travel-Assistant.md',
  270. '第十四章 自动化深度研究智能体.md': 'Chapter14-Automated-Deep-Research-Agent.md',
  271. '第十五章 构建赛博小镇.md': 'Chapter15-Building-Cyber-Town.md',
  272. '第十六章 毕业设计.md': 'Chapter16-Graduation-Project.md'
  273. },
  274. // 英文 -> 中文
  275. 'en2zh': {
  276. 'README_EN.md': 'README.md',
  277. 'Preface.md': '前言.md',
  278. 'Chapter1-Introduction-to-Agents.md': '第一章 初识智能体.md',
  279. 'Chapter2-History-of-Agents.md': '第二章 智能体发展史.md',
  280. 'Chapter3-Fundamentals-of-Large-Language-Models.md': '第三章 大语言模型基础.md',
  281. 'Chapter4-Building-Classic-Agent-Paradigms.md': '第四章 智能体经典范式构建.md',
  282. 'Chapter5-Building-Agents-with-Low-Code-Platforms.md': '第五章 基于低代码平台的智能体搭建.md',
  283. 'Chapter6-Framework-Development-Practice.md': '第六章 框架开发实践.md',
  284. 'Chapter7-Building-Your-Agent-Framework.md': '第七章 构建你的Agent框架.md',
  285. 'Chapter8-Memory-and-Retrieval.md': '第八章 记忆与检索.md',
  286. 'Chapter9-Context-Engineering.md': '第九章 上下文工程.md',
  287. 'Chapter10-Agent-Communication-Protocols.md': '第十章 智能体通信协议.md',
  288. 'Chapter11-Agentic-RL.md': '第十一章 Agentic-RL.md',
  289. 'Chapter12-Agent-Performance-Evaluation.md': '第十二章 智能体性能评估.md',
  290. 'Chapter13-Intelligent-Travel-Assistant.md': '第十三章 智能旅行助手.md',
  291. 'Chapter14-Automated-Deep-Research-Agent.md': '第十四章 自动化深度研究智能体.md',
  292. 'Chapter15-Building-Cyber-Town.md': '第十五章 构建赛博小镇.md',
  293. 'Chapter16-Graduation-Project.md': '第十六章 毕业设计.md'
  294. }
  295. };
  296. function switchLanguage() {
  297. const currentHash = window.location.hash;
  298. const langBtn = document.getElementById('langBtn');
  299. // 检测当前语言
  300. if (currentHash.includes('/en/')) {
  301. // 从英文切换到中文
  302. localStorage.setItem('preferredLanguage', 'zh');
  303. let newHash = currentHash.replace('#/', '').replace('en/', '');
  304. // 提取文件名
  305. const parts = newHash.split('/');
  306. const filename = parts[parts.length - 1];
  307. // 查找对应的中文文件名
  308. if (chapterMapping.en2zh[filename]) {
  309. parts[parts.length - 1] = chapterMapping.en2zh[filename];
  310. newHash = '#/' + parts.join('/');
  311. } else {
  312. newHash = '#/';
  313. }
  314. window.location.hash = newHash;
  315. langBtn.textContent = 'English';
  316. window.$docsify.pagination.previousText = '上一章节';
  317. window.$docsify.pagination.nextText = '下一章节';
  318. } else {
  319. // 从中文切换到英文
  320. localStorage.setItem('preferredLanguage', 'en');
  321. let path = currentHash.replace('#/', '');
  322. if (path === '' || path === '/') {
  323. // 首页
  324. window.location.hash = '#/en/README_EN.md';
  325. } else {
  326. // 提取文件名
  327. const parts = path.split('/');
  328. const filename = parts[parts.length - 1];
  329. // 查找对应的英文文件名
  330. if (chapterMapping.zh2en[filename]) {
  331. parts[parts.length - 1] = chapterMapping.zh2en[filename];
  332. window.location.hash = '#/en/' + parts.join('/');
  333. } else {
  334. window.location.hash = '#/en/README_EN.md';
  335. }
  336. }
  337. langBtn.textContent = '中文';
  338. window.$docsify.pagination.previousText = 'Previous';
  339. window.$docsify.pagination.nextText = 'Next';
  340. }
  341. // 重新加载页面以应用新的 sidebar
  342. window.location.reload();
  343. }
  344. // 页面加载时设置按钮文本和检查语言偏好
  345. window.addEventListener('load', function() {
  346. const currentHash = window.location.hash;
  347. const langBtn = document.getElementById('langBtn');
  348. const preferredLang = localStorage.getItem('preferredLanguage');
  349. // 只有在用户明确设置了语言偏好后,才自动切换
  350. // 首次访问(没有偏好设置)时,默认显示中文版
  351. if (preferredLang) {
  352. // 如果用户有语言偏好,且当前 URL 不匹配偏好,则自动切换
  353. if (preferredLang === 'en' && !currentHash.includes('/en/')) {
  354. // 用户偏好英文,但当前是中文页面
  355. let path = currentHash.replace('#/', '');
  356. if (path === '' || path === '/') {
  357. window.location.hash = '#/en/README_EN.md';
  358. } else {
  359. const parts = path.split('/');
  360. const filename = parts[parts.length - 1];
  361. if (chapterMapping.zh2en[filename]) {
  362. parts[parts.length - 1] = chapterMapping.zh2en[filename];
  363. window.location.hash = '#/en/' + parts.join('/');
  364. }
  365. }
  366. } else if (preferredLang === 'zh' && currentHash.includes('/en/')) {
  367. // 用户偏好中文,但当前是英文页面
  368. let newHash = currentHash.replace('#/', '').replace('en/', '');
  369. const parts = newHash.split('/');
  370. const filename = parts[parts.length - 1];
  371. if (chapterMapping.en2zh[filename]) {
  372. parts[parts.length - 1] = chapterMapping.en2zh[filename];
  373. window.location.hash = '#/' + parts.join('/');
  374. }
  375. }
  376. }
  377. // 设置按钮文本
  378. if (currentHash.includes('/en/')) {
  379. langBtn.textContent = '中文';
  380. } else {
  381. langBtn.textContent = 'English';
  382. }
  383. });
  384. </script>
  385. </body>
  386. </html>