Skip to content

Commit f9bfe5e

Browse files
committed
Fix docs language switching
1 parent 37a9fef commit f9bfe5e

3 files changed

Lines changed: 152 additions & 0 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
(() => {
2+
const script = document.currentScript;
3+
const scriptUrl = new URL(
4+
script?.getAttribute("src") ?? "javascripts/language-switcher.js",
5+
window.location.href
6+
);
7+
const siteBasePath = scriptUrl.pathname.replace(/\/javascripts\/language-switcher\.js$/, "/");
8+
9+
const trimSlashes = (value) => value.replace(/^\/+|\/+$/g, "");
10+
const withTrailingSlash = (value) => value.endsWith("/") ? value : `${value}/`;
11+
const normalizePagePath = (pathname) => {
12+
const decoded = decodeURI(pathname)
13+
.replace(/\/index\.html$/, "/")
14+
.replace(/\.html$/, "/");
15+
return withTrailingSlash(decoded);
16+
};
17+
const sitePath = (relativePath) => {
18+
const clean = trimSlashes(relativePath);
19+
return `${siteBasePath}${clean ? `${clean}/` : ""}`.replace(/\/{2,}/g, "/");
20+
};
21+
const currentRelativePath = () => {
22+
const pathname = normalizePagePath(window.location.pathname);
23+
return pathname.startsWith(siteBasePath)
24+
? trimSlashes(pathname.slice(siteBasePath.length))
25+
: trimSlashes(pathname);
26+
};
27+
const languageTarget = (language) => {
28+
const current = currentRelativePath();
29+
30+
if (language === "en") {
31+
if (!current || current === "zh/home") {
32+
return sitePath("");
33+
}
34+
if (current === "zh") {
35+
return sitePath("en");
36+
}
37+
if (current.startsWith("zh/")) {
38+
return sitePath(`en/${current.slice(3)}`);
39+
}
40+
return sitePath(current);
41+
}
42+
43+
if (language === "zh") {
44+
if (!current) {
45+
return sitePath("zh/home");
46+
}
47+
if (current === "en") {
48+
return sitePath("zh");
49+
}
50+
if (current.startsWith("en/")) {
51+
return sitePath(`zh/${current.slice(3)}`);
52+
}
53+
return sitePath(current);
54+
}
55+
56+
return sitePath("");
57+
};
58+
const applyLanguageTargets = () => {
59+
for (const link of document.querySelectorAll('a[hreflang="en"], a[hreflang="zh"]')) {
60+
const language = link.getAttribute("hreflang");
61+
link.setAttribute("href", languageTarget(language));
62+
}
63+
};
64+
65+
if (window.document$?.subscribe) {
66+
window.document$.subscribe(applyLanguageTargets);
67+
} else {
68+
document.addEventListener("DOMContentLoaded", applyLanguageTargets);
69+
applyLanguageTargets();
70+
}
71+
})();

docs/zh/home.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
hide:
3+
- navigation
4+
- toc
5+
- edit
6+
---
7+
8+
<div class="df-home" markdown>
9+
10+
<section class="df-home-hero" markdown>
11+
12+
<p class="df-kicker">开源数据智能体工作台</p>
13+
14+
# DataFoundry
15+
16+
面向企业数据任务的受控 Data Agent 工作流。将自然语言分析转化为理解 Schema、只读执行、可回放、可审计的数据工作。
17+
18+
<div class="df-actions" markdown>
19+
[快速开始](quick-start.md){ .df-button .df-button-primary }
20+
[阅读文档](index.md){ .df-button }
21+
[GitHub](https://github.com/datagallery-lab/datafoundry){ .df-button }
22+
</div>
23+
24+
</section>
25+
26+
<figure class="df-home-shot" markdown>
27+
![DataFoundry Web 工作台](../assets/readme/gui-demo.gif){ .df-shot }
28+
<figcaption>Web 工作台、终端工作流和后端运行时共享同一套受控任务模型。</figcaption>
29+
</figure>
30+
31+
<section class="df-proof-grid" markdown>
32+
33+
<div class="df-proof" markdown>
34+
### 受控执行
35+
Schema 检查、数据源策略、只读 SQL、行数限制、脱敏与审计都由 Data Gateway 统一约束。
36+
</div>
37+
38+
<div class="df-proof" markdown>
39+
### 可回放工作
40+
Web、TUI 和 API 客户端共享同一套运行状态、事件流、产物和任务历史。
41+
</div>
42+
43+
<div class="df-proof" markdown>
44+
### 统一上下文
45+
文件、知识库、技能、工具、记忆和数据源选择在后端策略下编译成可控上下文。
46+
</div>
47+
48+
</section>
49+
50+
## 选择合适的开始路径
51+
52+
<div class="df-grid df-route-grid" markdown>
53+
54+
<div class="df-card" markdown>
55+
### 本地试用
56+
启动工作台,并基于内置 DuckDB demo 完成第一次数据分析。
57+
58+
[快速开始](quick-start.md)
59+
</div>
60+
61+
<div class="df-card" markdown>
62+
### 理解系统
63+
了解运行时、安全边界和 Data Gateway 架构。
64+
65+
[架构概览](architecture/overview.md)
66+
</div>
67+
68+
<div class="df-card" markdown>
69+
### 接入 API
70+
使用 REST 配置 API 与 Agent Runtime / AG-UI 入口。
71+
72+
[API 参考](reference/rest-api.md)
73+
</div>
74+
75+
</div>
76+
77+
</div>

mkdocs.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ theme:
3333
extra_css:
3434
- stylesheets/extra.css
3535

36+
extra_javascript:
37+
- javascripts/language-switcher.js
38+
3639
extra:
3740
social:
3841
- icon: fontawesome/brands/github
@@ -71,6 +74,7 @@ nav:
7174
- Examples:
7275
- DTC growth analysis demo: en/examples/dtc-growth-demo.md
7376
- 简体中文:
77+
- 产品首页: zh/home.md
7478
- zh/index.md
7579
- 产品概览: zh/overview.md
7680
- 快速开始: zh/quick-start.md

0 commit comments

Comments
 (0)