| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Hello-Agents</title>
- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
- <meta name="description" content="Description">
- <meta name="viewport"
- content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
- <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify@latest/lib/themes/vue.css">
- <style>
- /* 语言切换按钮样式 */
- .lang-switch {
- position: fixed;
- top: 20px;
- right: 80px;
- z-index: 999;
- }
- .lang-switch button {
- background: #42b983;
- color: white;
- border: none;
- padding: 8px 16px;
- border-radius: 4px;
- cursor: pointer;
- font-size: 14px;
- transition: background 0.3s;
- }
- .lang-switch button:hover {
- background: #33a06f;
- }
- /* Giscus 评论区样式 */
- .giscus-container {
- margin-top: 60px;
- padding-top: 40px;
- border-top: 1px solid #eee;
- }
- /* 可折叠评论区标题 */
- .giscus-toggle {
- display: flex;
- align-items: center;
- justify-content: space-between;
- cursor: pointer;
- padding: 15px 20px;
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
- border-radius: 8px;
- margin-bottom: 20px;
- transition: all 0.3s ease;
- box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
- }
- .giscus-toggle:hover {
- transform: translateY(-2px);
- box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
- }
- .giscus-toggle-title {
- font-size: 1.3em;
- font-weight: 600;
- color: white;
- margin: 0;
- display: flex;
- align-items: center;
- gap: 10px;
- }
- .giscus-toggle-icon {
- font-size: 1.2em;
- transition: transform 0.3s ease;
- color: white;
- }
- .giscus-toggle-icon.expanded {
- transform: rotate(180deg);
- }
- .giscus-content {
- max-height: 0;
- overflow: hidden;
- transition: max-height 0.4s ease-out, opacity 0.3s ease;
- opacity: 0;
- }
- .giscus-content.expanded {
- max-height: 2000px;
- opacity: 1;
- transition: max-height 0.5s ease-in, opacity 0.4s ease;
- }
- .giscus-hint {
- font-size: 0.9em;
- color: rgba(255, 255, 255, 0.9);
- margin: 0;
- }
- </style>
- </head>
- <body>
- <!-- 语言切换按钮 -->
- <div class="lang-switch">
- <button id="langBtn" onclick="switchLanguage()">English</button>
- </div>
- <div id="app"></div>
- <script src="//cdn.jsdelivr.net/npm/mermaid@8.0.0-rc.8/dist/mermaid.min.js"></script>
- <script>
- window.$docsify = {
- name: 'Hello-Agents',
- repo: 'https://github.com/datawhalechina/Hello-Agents',
- loadSidebar: true,
- auto2top: true,
- subMaxLevel: 3,
- relativePath: false,
- alias: {
- // 英文路径映射
- '/en/README.md': '/README_EN.md',
- '/en/Preface.md': '/Preface.md',
- '/en/_sidebar.md': '/_sidebar_en.md',
- '/en/chapter(\\d+)/Chapter(.*)': '/chapter$1/Chapter$2',
- // 默认中文侧边栏
- '/_sidebar.md': '/_sidebar.md'
- },
- pagination: {
- previousText: '上一章节',
- nextText: '下一章节',
- },
- count: {
- countable: true,
- fontsize: '0.9em',
- color: 'rgb(90,90,90)',
- language: 'chinese'
- },
- // 多语言配置
- fallbackLanguages: ['en'],
- nameLink: {
- '/en/': '#/en/',
- '/': '#/'
- },
- // 使用钩子动态处理侧边栏
- plugins: [
- function(hook, vm) {
- // 在每次路由变化时检查语言偏好
- hook.beforeEach(function(content) {
- const preferredLang = localStorage.getItem('preferredLanguage');
- const currentPath = vm.route.path;
- // 根据当前路径或语言偏好更新分页文本
- if (currentPath.includes('/en/') || preferredLang === 'en') {
- window.$docsify.pagination.previousText = 'Previous';
- window.$docsify.pagination.nextText = 'Next';
- } else {
- window.$docsify.pagination.previousText = '上一章节';
- window.$docsify.pagination.nextText = '下一章节';
- }
- return content;
- });
- // 在页面渲染后添加 Giscus 评论区
- hook.doneEach(function() {
- // 检查是否是章节页面(排除首页和前言)
- const currentPath = vm.route.path;
- const isChapterPage = currentPath.includes('chapter') ||
- currentPath.includes('Chapter') ||
- currentPath.includes('第') && currentPath.includes('章');
- if (!isChapterPage) {
- return; // 非章节页面不显示评论区
- }
- // 移除旧的评论区
- const oldGiscus = document.querySelector('.giscus-container');
- if (oldGiscus) {
- oldGiscus.remove();
- }
- // 创建评论区容器
- const giscusContainer = document.createElement('div');
- giscusContainer.className = 'giscus-container';
- // 获取语言设置
- const preferredLang = localStorage.getItem('preferredLanguage');
- const isEnglish = currentPath.includes('/en/') || preferredLang === 'en';
- // 创建可折叠的标题栏
- const toggleButton = document.createElement('div');
- toggleButton.className = 'giscus-toggle';
- const titleDiv = document.createElement('div');
- titleDiv.className = 'giscus-toggle-title';
- titleDiv.innerHTML = isEnglish
- ? '💬 Discussion & Questions'
- : '💬 讨论与提问';
- const hintText = document.createElement('p');
- hintText.className = 'giscus-hint';
- hintText.textContent = isEnglish
- ? 'Click to expand/collapse'
- : '点击展开/收起';
- const iconSpan = document.createElement('span');
- iconSpan.className = 'giscus-toggle-icon';
- iconSpan.textContent = '▼';
- const titleWrapper = document.createElement('div');
- titleWrapper.appendChild(titleDiv);
- titleWrapper.appendChild(hintText);
- toggleButton.appendChild(titleWrapper);
- toggleButton.appendChild(iconSpan);
- // 创建评论内容容器
- const contentDiv = document.createElement('div');
- contentDiv.className = 'giscus-content';
- // 创建 Giscus 脚本
- const giscusScript = document.createElement('script');
- giscusScript.src = 'https://giscus.app/client.js';
- giscusScript.setAttribute('data-repo', 'datawhalechina/hello-agents');
- giscusScript.setAttribute('data-repo-id', 'R_kgDOPrUECg');
- giscusScript.setAttribute('data-category', '💬 Exercises & Q&A');
- giscusScript.setAttribute('data-category-id', 'DIC_kwDOPrUECs4Cxfyu');
- giscusScript.setAttribute('data-mapping', 'pathname');
- giscusScript.setAttribute('data-strict', '0');
- giscusScript.setAttribute('data-reactions-enabled', '1');
- giscusScript.setAttribute('data-emit-metadata', '0');
- giscusScript.setAttribute('data-input-position', 'top');
- giscusScript.setAttribute('data-theme', 'preferred_color_scheme');
- giscusScript.setAttribute('data-lang', isEnglish ? 'en' : 'zh-CN');
- giscusScript.setAttribute('data-loading', 'lazy');
- giscusScript.crossOrigin = 'anonymous';
- giscusScript.async = true;
- contentDiv.appendChild(giscusScript);
- // 组装评论区
- giscusContainer.appendChild(toggleButton);
- giscusContainer.appendChild(contentDiv);
- // 添加折叠/展开功能
- let isExpanded = false;
- toggleButton.addEventListener('click', function() {
- isExpanded = !isExpanded;
- if (isExpanded) {
- contentDiv.classList.add('expanded');
- iconSpan.classList.add('expanded');
- } else {
- contentDiv.classList.remove('expanded');
- iconSpan.classList.remove('expanded');
- }
- });
- // 将评论区添加到内容区域
- const article = document.querySelector('article.markdown-section');
- if (article) {
- article.appendChild(giscusContainer);
- }
- });
- }
- ]
- }
- </script>
- <!-- Put them above docsify.min.js -->
- <script src="//cdn.jsdelivr.net/npm/docsify@latest/lib/docsify.min.js"></script>
- <!-- code render-->
- <script src="//cdn.jsdelivr.net/npm/prismjs@latest/components/prism-bash.js"></script>
- <script src="//cdn.jsdelivr.net/npm/prismjs@latest/components/prism-python.js"></script>
- <script src="//cdn.jsdelivr.net/npm/docsify-pagination@latest/dist/docsify-pagination.min.js"></script>
- <script src="//cdn.jsdelivr.net/npm/docsify-copy-code"></script>
- <script src="https://cdn.jsdelivr.net/npm/katex@latest/dist/katex.min.js"></script>
- <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/katex@latest/dist/katex.min.css" />
- <script src="https://cdn.jsdelivr.net/npm/marked@3"></script>
- <!-- CDN files for docsify-katex -->
- <script src="//cdn.jsdelivr.net/npm/docsify-katex@latest/dist/docsify-katex.js"></script>
- <!-- 字数统计 -->
- <script src="//unpkg.com/docsify-count/dist/countable.js"></script>
- <!-- 语言切换脚本 -->
- <script>
- // 章节文件名映射
- const chapterMapping = {
- // 中文 -> 英文
- 'zh2en': {
- 'README.md': 'README_EN.md',
- '前言.md': 'Preface.md',
- '第一章 初识智能体.md': 'Chapter1-Introduction-to-Agents.md',
- '第二章 智能体发展史.md': 'Chapter2-History-of-Agents.md',
- '第三章 大语言模型基础.md': 'Chapter3-Fundamentals-of-Large-Language-Models.md',
- '第四章 智能体经典范式构建.md': 'Chapter4-Building-Classic-Agent-Paradigms.md',
- '第五章 基于低代码平台的智能体搭建.md': 'Chapter5-Building-Agents-with-Low-Code-Platforms.md',
- '第六章 框架开发实践.md': 'Chapter6-Framework-Development-Practice.md',
- '第七章 构建你的Agent框架.md': 'Chapter7-Building-Your-Agent-Framework.md',
- '第八章 记忆与检索.md': 'Chapter8-Memory-and-Retrieval.md',
- '第九章 上下文工程.md': 'Chapter9-Context-Engineering.md',
- '第十章 智能体通信协议.md': 'Chapter10-Agent-Communication-Protocols.md',
- '第十一章 Agentic-RL.md': 'Chapter11-Agentic-RL.md',
- '第十二章 智能体性能评估.md': 'Chapter12-Agent-Performance-Evaluation.md',
- '第十三章 智能旅行助手.md': 'Chapter13-Intelligent-Travel-Assistant.md',
- '第十四章 自动化深度研究智能体.md': 'Chapter14-Automated-Deep-Research-Agent.md',
- '第十五章 构建赛博小镇.md': 'Chapter15-Building-Cyber-Town.md',
- '第十六章 毕业设计.md': 'Chapter16-Graduation-Project.md'
- },
- // 英文 -> 中文
- 'en2zh': {
- 'README_EN.md': 'README.md',
- 'Preface.md': '前言.md',
- 'Chapter1-Introduction-to-Agents.md': '第一章 初识智能体.md',
- 'Chapter2-History-of-Agents.md': '第二章 智能体发展史.md',
- 'Chapter3-Fundamentals-of-Large-Language-Models.md': '第三章 大语言模型基础.md',
- 'Chapter4-Building-Classic-Agent-Paradigms.md': '第四章 智能体经典范式构建.md',
- 'Chapter5-Building-Agents-with-Low-Code-Platforms.md': '第五章 基于低代码平台的智能体搭建.md',
- 'Chapter6-Framework-Development-Practice.md': '第六章 框架开发实践.md',
- 'Chapter7-Building-Your-Agent-Framework.md': '第七章 构建你的Agent框架.md',
- 'Chapter8-Memory-and-Retrieval.md': '第八章 记忆与检索.md',
- 'Chapter9-Context-Engineering.md': '第九章 上下文工程.md',
- 'Chapter10-Agent-Communication-Protocols.md': '第十章 智能体通信协议.md',
- 'Chapter11-Agentic-RL.md': '第十一章 Agentic-RL.md',
- 'Chapter12-Agent-Performance-Evaluation.md': '第十二章 智能体性能评估.md',
- 'Chapter13-Intelligent-Travel-Assistant.md': '第十三章 智能旅行助手.md',
- 'Chapter14-Automated-Deep-Research-Agent.md': '第十四章 自动化深度研究智能体.md',
- 'Chapter15-Building-Cyber-Town.md': '第十五章 构建赛博小镇.md',
- 'Chapter16-Graduation-Project.md': '第十六章 毕业设计.md'
- }
- };
- function switchLanguage() {
- const currentHash = window.location.hash;
- const langBtn = document.getElementById('langBtn');
- // 检测当前语言
- if (currentHash.includes('/en/')) {
- // 从英文切换到中文
- localStorage.setItem('preferredLanguage', 'zh');
- let newHash = currentHash.replace('#/', '').replace('en/', '');
- // 提取文件名
- const parts = newHash.split('/');
- const filename = parts[parts.length - 1];
- // 查找对应的中文文件名
- if (chapterMapping.en2zh[filename]) {
- parts[parts.length - 1] = chapterMapping.en2zh[filename];
- newHash = '#/' + parts.join('/');
- } else {
- newHash = '#/';
- }
- window.location.hash = newHash;
- langBtn.textContent = 'English';
- window.$docsify.pagination.previousText = '上一章节';
- window.$docsify.pagination.nextText = '下一章节';
- } else {
- // 从中文切换到英文
- localStorage.setItem('preferredLanguage', 'en');
- let path = currentHash.replace('#/', '');
- if (path === '' || path === '/') {
- // 首页
- window.location.hash = '#/en/README_EN.md';
- } else {
- // 提取文件名
- const parts = path.split('/');
- const filename = parts[parts.length - 1];
- // 查找对应的英文文件名
- if (chapterMapping.zh2en[filename]) {
- parts[parts.length - 1] = chapterMapping.zh2en[filename];
- window.location.hash = '#/en/' + parts.join('/');
- } else {
- window.location.hash = '#/en/README_EN.md';
- }
- }
- langBtn.textContent = '中文';
- window.$docsify.pagination.previousText = 'Previous';
- window.$docsify.pagination.nextText = 'Next';
- }
- // 重新加载页面以应用新的 sidebar
- window.location.reload();
- }
- // 页面加载时设置按钮文本和检查语言偏好
- window.addEventListener('load', function() {
- const currentHash = window.location.hash;
- const langBtn = document.getElementById('langBtn');
- const preferredLang = localStorage.getItem('preferredLanguage');
- // 只有在用户明确设置了语言偏好后,才自动切换
- // 首次访问(没有偏好设置)时,默认显示中文版
- if (preferredLang) {
- // 如果用户有语言偏好,且当前 URL 不匹配偏好,则自动切换
- if (preferredLang === 'en' && !currentHash.includes('/en/')) {
- // 用户偏好英文,但当前是中文页面
- let path = currentHash.replace('#/', '');
- if (path === '' || path === '/') {
- window.location.hash = '#/en/README_EN.md';
- } else {
- const parts = path.split('/');
- const filename = parts[parts.length - 1];
- if (chapterMapping.zh2en[filename]) {
- parts[parts.length - 1] = chapterMapping.zh2en[filename];
- window.location.hash = '#/en/' + parts.join('/');
- }
- }
- } else if (preferredLang === 'zh' && currentHash.includes('/en/')) {
- // 用户偏好中文,但当前是英文页面
- let newHash = currentHash.replace('#/', '').replace('en/', '');
- const parts = newHash.split('/');
- const filename = parts[parts.length - 1];
- if (chapterMapping.en2zh[filename]) {
- parts[parts.length - 1] = chapterMapping.en2zh[filename];
- window.location.hash = '#/' + parts.join('/');
- }
- }
- }
- // 设置按钮文本
- if (currentHash.includes('/en/')) {
- langBtn.textContent = '中文';
- } else {
- langBtn.textContent = 'English';
- }
- });
- </script>
- </body>
- </html>
|