Skip to content

Commit d6f362a

Browse files
wuyuantravilyu
authored andcommitted
refactor: 升级为最新版 vite-press
1 parent 2be477f commit d6f362a

140 files changed

Lines changed: 7027 additions & 21245 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/build.yml‎

Lines changed: 26 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
1+
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code, and run tests across different versions of node
22
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
33

44
name: Build CI
@@ -28,87 +28,62 @@ jobs:
2828
strategy:
2929
matrix:
3030
node-version:
31-
- 12.x
31+
- 22.x
3232
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
3333

3434
steps:
3535
- name: Checkout
36-
uses: actions/checkout@v3
36+
uses: actions/checkout@v4
3737
with:
3838
fetch-depth: 0
3939

40-
- name: Use Node.js ${{ matrix.node-version }}
41-
uses: actions/setup-node@v3
42-
with:
43-
node-version: ${{ matrix.node-version }}
44-
4540
- name: Install pnpm
46-
run: npm install -g pnpm@6
47-
48-
- name: Get pnpm store directory
49-
id: pnpm-cache
50-
run: |
51-
echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
41+
uses: pnpm/action-setup@v4
5242

53-
- uses: actions/cache@v3
54-
name: Setup pnpm cache
43+
- name: Use Node.js ${{ matrix.node-version }}
44+
uses: actions/setup-node@v4
5545
with:
56-
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
57-
key: docs-${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
58-
restore-keys: |
59-
docs-${{ runner.os }}-pnpm-store-
46+
node-version: ${{ matrix.node-version }}
47+
cache: 'pnpm'
6048

6149
- name: Get current branch
6250
id: get_branch
6351
run: |
6452
if [ "$GITHUB_EVENT_NAME" == "push" ]; then
65-
echo "BRANCH=${GITHUB_REF##*/}" >> $GITHUB_ENV
53+
echo "BRANCH=${GITHUB_REF##*/}" >> $GITHUB_ENV
6654
elif [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then
67-
echo "BRANCH=$GITHUB_HEAD_REF" >> $GITHUB_ENV
55+
echo "BRANCH=$GITHUB_HEAD_REF" >> $GITHUB_ENV
6856
fi
6957
7058
- name: Node build
7159
shell: bash
72-
env:
73-
NODE_OPTIONS: "--max-old-space-size=4096"
7460
run: |
75-
# 清理缓存以释放内存
76-
pnpm store prune || true
77-
# 安装依赖
78-
pnpm install gray-matter json2yaml
79-
# 显示内存使用情况
80-
free -h
81-
# 执行构建步骤
82-
node --max-old-space-size=4096 addTime.js
83-
node --max-old-space-size=4096 addTime.js ./translate/translated
84-
node --max-old-space-size=4096 copy-file.js ./docs/zh ./translate/translated false
61+
pnpm install --frozen-lockfile
62+
# 英文翻译树:补充中文侧资源后合并进 docs/(英文页位于根路径)
63+
node copy-file.js ./docs/zh ./translate/translated false
8564
rm -rf translate/translated/README.md
8665
mv translate/translated/* ./docs
8766
rm -rf ./docs/map.txt
88-
pnpm install
89-
node --max-old-space-size=4096 downloadFile.js ${{ env.BRANCH }}
90-
node --max-old-space-size=4096 downloadCSV.js ${{ env.BRANCH }}
91-
# 清理内存
92-
node --max-old-space-size=4096 -e "if (global.gc) global.gc()"
67+
node downloadFile.js ${{ env.BRANCH }}
68+
node downloadCSV.js ${{ env.BRANCH }}
69+
# VitePress 构建(自带死链检测,产物输出 dist/;vdoing 旧语法
70+
# (code-tabs、相对链接)由 .vitepress/markdown/ 下的适配插件在渲染期转换)
71+
pnpm run build
9372
pnpm run build
94-
node --max-old-space-size=4096 copy-file.js
73+
# 资源文件(json/txt/图片等)按去序号路径拷贝到 dist
74+
node copy-file.js
9575
9676
- name: Set up Docker Buildx
97-
uses: docker/setup-buildx-action@v1
77+
uses: docker/setup-buildx-action@v3
9878

9979
- name: Log in to ALIYUN Docker Registry
10080
if: ${{ github.repository == 'deepflowio/docs'}}
101-
uses: docker/login-action@v2
81+
uses: docker/login-action@v3
10282
with:
10383
registry: "${{ secrets.REGISTRY_ALIYUN_ADDR }}"
10484
username: "${{ secrets.REGISTRY_ALIYUN_USER }}"
10585
password: "${{ secrets.ALIYUN_DF_CLOUD_REGISTRY_PASSWORD }}"
10686

107-
# - name: debug
108-
# shell: bash
109-
# run: |
110-
# more $GITHUB_EVENT_PATH
111-
11287
- name: set env
11388
if: ${{ github.event_name == 'pull_request' && github.repository == 'deepflowio/docs' && github.event.pull_request.base.ref == 'main' }}
11489
run: |
@@ -125,8 +100,8 @@ jobs:
125100
echo "IMAGE_TAG_PREFIX=${{ github.ref_name }}"|sed 's|main|latest|' >> $GITHUB_ENV
126101
127102
- name: Build and push docs image
128-
if: ${{ github.repository == 'deepflowio/docs'}}
129-
uses: docker/build-push-action@v2
103+
if: ${{ github.repository == 'deepflowio/docs'}}
104+
uses: docker/build-push-action@v6
130105
with:
131106
context: .
132107
file: Dockerfile
@@ -152,7 +127,7 @@ jobs:
152127
shell: bash
153128
if: ${{ github.repository == 'deepflowio/docs'}}
154129
run: |
155-
curl -X POST -H "Content-Type: application/json" -d \
130+
curl -X POST -H "Content-Type: application/json" -d \
156131
'{"msg_type":"interactive","card":
157132
{
158133
"config": {
@@ -191,7 +166,7 @@ jobs:
191166
kubectl set image -n deepservice-test deployment deepservice-docs deepservice-docs=${{ secrets.REGISTRY_ALIYUN_ADDR }}/deepservice/${{ env.IMAGE }}:${{ env.IMAGE_TAG_PREFIX }}-${{ github.run_id }}-${{ github.run_attempt }}
192167
193168
- name: update
194-
if: ${{ github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main' && github.repository == 'deepflowio/docs' }}
169+
if: ${{ github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main' && github.repository == 'deepflowio/docs' }}
195170
shell: bash
196171
run: |
197172
kubectl set image -n deepservice deployment deepservice-docs deepservice-docs=${{ secrets.REGISTRY_ALIYUN_ADDR }}/deepservice/${{ env.IMAGE }}:${{ env.IMAGE_TAG_PREFIX }}-${{ github.run_id }}-${{ github.run_attempt }}

‎.gitignore‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,12 @@ node_modules
77

88
#build
99
/dist/
10+
/dist-doc-only/
11+
12+
# CI/本地经 downloadFile.js 下载生成的 Agent 配置页(downloadFile.json)
13+
/docs/07-configuration/
14+
/docs/zh/07-configuration/
15+
16+
# vitepress
17+
.vitepress/cache/
18+
/cache/

‎.vitepress/config.mts‎

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
import { defineConfig } from 'vitepress'
2+
import footnote from 'markdown-it-footnote'
3+
import taskLists from 'markdown-it-task-lists'
4+
import container from 'markdown-it-container'
5+
import { withMermaid } from 'vitepress-plugin-mermaid'
6+
import rewrites from './rewrites.generated.json'
7+
import { sidebar } from './sidebar'
8+
import { legacyCodeTabs } from './markdown/legacy-code-tabs'
9+
import { legacyLinks } from './markdown/legacy-links'
10+
11+
const GITHUB_DOCS = 'https://github.com/deepflowio/docs'
12+
13+
// 构建变体(由 package.json 的 dev:doc-only / build:doc-only /
14+
// preview:doc-only 注入 DOCS_MODE=doc-only):
15+
// 默认 —— 供主站嵌入,全站导航栏/页脚始终隐藏(产物 dist);
16+
// doc-only —— 独立文档站,渲染 doc 专属顶栏(DocHeader)、无页脚
17+
// (产物 dist-doc-only)。差异均由构建期写进 head 的
18+
// html 类标记驱动,见下方 head 与 theme/custom.css
19+
const DOC_ONLY = process.env.DOCS_MODE === 'doc-only'
20+
21+
export default withMermaid(
22+
defineConfig({
23+
lang: 'en-US',
24+
title: 'DeepFlow',
25+
description:
26+
'DeepFlow leverages eBPF and Wasm to achieve zero-code and full-stack observability, enabling continuous innovation in cloud-native and AI applications.',
27+
28+
srcDir: 'docs',
29+
// 产物输出到仓库根 dist(默认是 .vitepress/dist),与 Dockerfile 的 COPY ./dist
30+
// 及 df-help 企业版 CI 的 mv ./docs/dist/* 对齐;doc-only 变体单独输出到
31+
// dist-doc-only,避免两种形态互相覆盖
32+
outDir: DOC_ONLY ? 'dist-doc-only' : 'dist',
33+
base: '/docs/',
34+
// 主题默认 dark(旧站观感)。'dark' 下 VitePress 优先读 localStorage
35+
// (vitepress-theme-appearance),无记录时回退此默认值,切换时写回;
36+
// 切换入口为侧边栏搜索栏左侧的主题按钮(SidebarActions)。
37+
// 注意 appearance 是根级配置项,放在 themeConfig 下不会生效(源码读
38+
// userConfig.appearance)
39+
appearance: 'dark',
40+
cleanUrls: true,
41+
lastUpdated: true,
42+
// 死链豁免:Agent 配置页(/configuration/agent)由 CI 构建前的
43+
// downloadFile.js 从 deepflow 主仓库下载生成(见 downloadFile.json 与
44+
// .github/workflows/build.yml),提交态仓库中无此文件,指向它的链接在
45+
// 本地构建时必然悬空。仅本地(无 CI 环境变量)豁免这两个精确地址;
46+
// CI 下不豁免,下载步骤失效时构建仍以死链失败兜底。本地要构建出该
47+
// 页面的完整产物,可先手动执行 `node downloadFile.js main`
48+
ignoreDeadLinks: process.env.CI ? [] : ['/configuration/agent', '/zh/configuration/agent'],
49+
sitemap: { hostname: 'https://deepflow.io' },
50+
51+
// URL 模型(与迁移前线上一致):
52+
// 英文页(CI 时由 translate/translated 合并进 docs/)位于根路径 clean URL;
53+
// 中文页位于 /zh/ 前缀下。映射由 scripts/gen-rewrites.mjs 生成。
54+
rewrites: rewrites as Record<string, string>,
55+
56+
locales: {
57+
root: {
58+
label: 'English',
59+
lang: 'en-US',
60+
description:
61+
'DeepFlow leverages eBPF and Wasm to achieve zero-code and full-stack observability, enabling continuous innovation in cloud-native and AI applications.',
62+
themeConfig: {
63+
nav: [
64+
{ text: 'Quick Start', link: '/guide/quick-start/5w-method' },
65+
{ text: 'Features', link: '/features/l7-protocols/overview' },
66+
{ text: 'Release Notes', link: '/release-notes/release-7.2-ce' }
67+
]
68+
}
69+
},
70+
zh: {
71+
label: '简体中文',
72+
lang: 'zh-CN',
73+
description:
74+
'DeepFlow 旨在为复杂的云原生和 AI 应用提供深度可观测性。DeepFlow 基于 eBPF 实现了应用性能指标、分布式追踪、持续性能剖析等观测信号的零侵扰(Zero Code)采集,并结合智能标签(SmartEncoding)技术实现了所有观测信号的全栈(Full Stack)关联和高效存取。',
75+
themeConfig: {
76+
nav: [
77+
{ text: '快速开始', link: '/zh/guide/quick-start/5w-method' },
78+
{ text: '功能特性', link: '/zh/features/l7-protocols/overview' },
79+
{ text: '版本发布', link: '/zh/release-notes/release-7.2-ce' }
80+
],
81+
outline: { level: [2, 3], label: '本页目录' },
82+
lastUpdated: { text: '上次更新' },
83+
docFooter: { prev: '上一篇', next: '下一篇' },
84+
returnToTopLabel: '回到顶部',
85+
sidebarMenuLabel: '菜单',
86+
darkModeSwitchLabel: '主题',
87+
lightModeSwitchTitle: '切换到浅色模式',
88+
darkModeSwitchTitle: '切换到深色模式',
89+
// 中文内容为源文件,英文为 CI 生成的机器翻译,只开放中文侧的编辑入口
90+
editLink: {
91+
pattern: `${GITHUB_DOCS}/edit/main/docs/:path`,
92+
text: '编辑此页'
93+
}
94+
}
95+
}
96+
},
97+
98+
head: [
99+
['link', { rel: 'icon', href: '/img/favicon.ico' }],
100+
['meta', { name: 'theme-color', content: '#0a72ef' }],
101+
// html 类标记(内联在 head 中于首帧前执行,无闪烁),配合
102+
// theme/custom.css 控制全站 chrome 的显隐:
103+
// - embedded:隐藏全站导航栏/页脚(SiteNavbar/SiteFooter)并清空其
104+
// 占位。首行的 iframe 检测保留(参考 eaf3930)——后续若恢复
105+
// "仅 iframe 嵌入时隐藏"的策略,删掉下方无条件标记即可;
106+
// 目前常规构建也始终隐藏
107+
// - doc-only:仅 doc-only 变体添加,恢复 doc 专属顶栏(DocHeader)
108+
// 的高度占位,页脚保持隐藏
109+
[
110+
'script',
111+
{},
112+
[
113+
"if (window.self !== window.top) document.documentElement.classList.add('embedded');",
114+
"document.documentElement.classList.add('embedded');",
115+
DOC_ONLY ? "document.documentElement.classList.add('doc-only');" : ''
116+
]
117+
.filter(Boolean)
118+
.join('')
119+
]
120+
],
121+
122+
markdown: {
123+
lineNumbers: true,
124+
config: (md) => {
125+
// vdoing 时代语法的运行时适配(内容文件保持原样,不改写)
126+
md.use(legacyCodeTabs)
127+
md.use(legacyLinks)
128+
md.use(footnote)
129+
md.use(taskLists)
130+
// 自定义容器示例:通过 markdown-it-container 注册(2.0 起可改为声明式
131+
// markdown.container.customContainers)
132+
md.use(container, 'success', {
133+
render: (tokens, idx) =>
134+
tokens[idx].nesting === 1
135+
? '<div class="tip custom-block"><p class="custom-block-title">SUCCESS</p>\n'
136+
: '</div>\n'
137+
})
138+
}
139+
},
140+
141+
// mermaid 由插件客户端代码动态 import,逃过 Vite 依赖扫描,未预构建时
142+
// 其内部对 dayjs(UMD)的 ESM 具名导入会在 dev 下报错,强制预构建修复
143+
vite: {
144+
optimizeDeps: {
145+
include: ['mermaid', 'dayjs']
146+
}
147+
},
148+
149+
themeConfig: {
150+
logo: '/img/logo.png',
151+
socialLinks: [{ icon: 'github', link: 'https://github.com/deepflowio/deepflow' }],
152+
sidebar,
153+
154+
search: {
155+
provider: 'local',
156+
options: {
157+
// MiniSearch 默认按空白分词,中文整句无法命中,改用 Intl.Segmenter 分词
158+
miniSearch: {
159+
options: {
160+
tokenize: (text: string) =>
161+
[...new Intl.Segmenter('zh-CN', { granularity: 'word' }).segment(text)].map(
162+
(s) => s.segment
163+
)
164+
}
165+
}
166+
}
167+
}
168+
}
169+
})
170+
)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// vdoing 时代 code-tabs 语法的运行时适配(内容文件保持原语法,不改写):
2+
//
3+
// ::: code-tabs#shell
4+
// @tab 标题
5+
// ```bash
6+
// ...
7+
// ```
8+
// :::
9+
//
10+
// 转换发生在 markdown-it 解析之后的 token 层:
11+
// 1. @tab 段落被移除,标题写入其后第一个围栏的 info(bash [标题])
12+
// 2. 容器 token 改名为 container_code-group_*,直接复用 VitePress
13+
// 内置 code-group 的渲染(标签页 UI、active 态、复制按钮全部原生)
14+
import container from 'markdown-it-container'
15+
import type MarkdownIt from 'markdown-it'
16+
17+
const TAB_RE = /^@tab\s+(.+)$/
18+
19+
export function legacyCodeTabs(md: MarkdownIt): void {
20+
md.use(container as any, 'code-tabs', {
21+
validate: (params: string) => /^code-tabs(#[\w-]+)?\s*$/.test(params.trim())
22+
})
23+
24+
md.core.ruler.push('legacy_code_tabs', (state) => {
25+
const tokens = state.tokens
26+
const removals: number[] = []
27+
28+
for (let i = 0; i < tokens.length; i++) {
29+
if (tokens[i].type !== 'container_code-tabs_open') continue
30+
31+
let title: string | null = null
32+
let j = i + 1
33+
for (; tokens[j].type !== 'container_code-tabs_close'; j++) {
34+
const t = tokens[j]
35+
// @tab 行解析为 paragraph_open + inline + paragraph_close
36+
if (t.type === 'paragraph_open' && tokens[j + 1]?.type === 'inline') {
37+
const m = tokens[j + 1].content.match(TAB_RE)
38+
if (m) {
39+
title = m[1].trim()
40+
removals.push(j, j + 1, j + 2)
41+
j += 2
42+
continue
43+
}
44+
}
45+
if (t.type === 'fence' && title !== null) {
46+
t.info = `${t.info.trim()} [${title}]`
47+
title = null
48+
}
49+
}
50+
51+
// 交给 VitePress 内置 code-group 渲染规则接管
52+
tokens[i].type = 'container_code-group_open'
53+
tokens[j].type = 'container_code-group_close'
54+
55+
i = j
56+
}
57+
58+
for (const idx of removals.sort((a, b) => b - a)) tokens.splice(idx, 1)
59+
})
60+
}

0 commit comments

Comments
 (0)