-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathconvert-config.sh
More file actions
executable file
·151 lines (140 loc) · 3.93 KB
/
convert-config.sh
File metadata and controls
executable file
·151 lines (140 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash
# 自动将docs.json导航tabs转换为VitePress config.mts
# 依赖: jq
set -e
DOCS_JSON="./docs.json"
OUTPUT="./.vitepress/config.mts"
if ! command -v jq &> /dev/null; then
echo "❌ jq未安装,请先安装 jq" >&2
exit 1
fi
if [ ! -f "$DOCS_JSON" ]; then
echo "❌ 未找到 $DOCS_JSON" >&2
exit 1
fi
echo "🔄 解析docs.json..."
# 生成nav
NAV=$(jq -c '
.navigation.tabs | map({
text: .tab,
link: (if .tab == "53AI Hub" then "/" else if .tab == "53AI Studio" then "/studio/" else if .tab == "53AI KM" then "/km/" else "/" end end end),
activeMatch: (if .tab == "53AI Hub" then "^/(?!studio|km)" else if .tab == "53AI Studio" then "^/studio/" else if .tab == "53AI KM" then "^/km/" else "^/" end end end)
})
' "$DOCS_JSON")
# 生成sidebar,一级分组collapsed: false,二级分组collapsed: true
SIDEBAR=$(jq -c '
.navigation.tabs | map({
(if .tab == "53AI Hub" then "/" else if .tab == "53AI Studio" then "/studio/" else if .tab == "53AI KM" then "/km/" else "/" end end end):
(.groups | map({
text: .group,
collapsible: true,
collapsed: false,
items: (
.pages | map(
if type == "string" then
{ text: (. | split("/") | last | gsub(".md$"; "")), link: . }
else
{ text: .group, collapsible: true, collapsed: true, items: (.pages | map({ text: (. | split("/") | last | gsub(".md$"; "")), link: . })) }
end
)
)
}))
}) | add
' "$DOCS_JSON")
# 读取标题
TITLE=$(jq -r '.name // "53AI"' "$DOCS_JSON")
echo "✅ 生成nav和sidebar"
# 输出config.mts
cat > "$OUTPUT" <<EOF
import { defineConfig } from 'vitepress'
// https://vitepress.dev/reference/site-config
// 此文件由 convert-config.sh 自动生成,请勿手动修改
export default defineConfig({
lang: 'zh',
title: " ",
description: "53AI知识库",
srcDir: '.',
// locales: {
// root: {
// label: '中文',
// lang: 'zh',
// },
// en: {
// label: 'English',
// lang: 'en',
// link: '/en',
// }
// },
ignoreDeadLinks: [
// 忽略所有包含 "localhost" 的链接
/localhost/,
/127.0.0.1/,
/192.168.1/,
// 或精确忽略特定链接
"http://localhost:3000"
],
head: [
// 百度统计
["script", {}, \`
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?2909a807282d29537229722a2ac6b45e";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
\`]
],
themeConfig: {
logo: '/logo/light.svg',
darkLogo: '/logo/dark.svg',
head: [
// 声明默认 Favicon(浏览器标签栏图标)
{
rel: 'icon',
type: 'image/svg+xml', // .svg 格式用此类型
href: '/favicon.svg'
},
// 百度统计
["script", {}, \`
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?2909a807282d29537229722a2ac6b45e";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
\`]
],
nav: $NAV,
sidebar: $SIDEBAR,
search: {
provider: 'local',
locales: {
locales: {
zh: {
translations: {
button: {
buttonText: '搜索文档',
buttonAriaLabel: '搜索文档'
},
modal: {
noResultsText: '无法找到相关结果',
resetButtonTitle: '清除查询条件',
footer: {
selectText: '选择',
navigateText: '切换'
}
}
}
}
}
}
},
socialLinks: [
{ icon: 'github', link: 'https://github.com/53AI/53AIHub' }
]
}
})
EOF
echo "🎉 config.mts已生成: $OUTPUT"