config.ts 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. import { createRequire } from 'node:module'
  2. import { defineAdditionalConfig, type DefaultTheme } from 'vitepress'
  3. import { builtinModulesApiSidebarItems, extensionModulesApiSidebarItems } from '../sidebar'
  4. import { posts } from '../.vitepress/data/zh-blog-data.js'
  5. const require = createRequire(import.meta.url)
  6. const pkg = require('vitepress/package.json')
  7. export default defineAdditionalConfig({
  8. lang: 'zh-Hans',
  9. description: '一个基于Lua的轻量级跨平台自动构建工具',
  10. themeConfig: {
  11. nav: nav(),
  12. search: { options: searchOptions() },
  13. sidebar: {
  14. '/zh/guide/': { base: '/zh/guide/', items: guideSidebar() },
  15. '/zh/api/description/': { base: '/zh/api/description/', items: descriptionApiSidebar() },
  16. '/zh/api/scripts/': { base: '/zh/api/scripts/', items: scriptsApiSidebar() },
  17. '/zh/examples/': { base: '/zh/examples/', items: examplesSidebar() },
  18. '/zh/about/': [
  19. {
  20. text: '关于',
  21. items: [
  22. { text: '在线赞助', link: '/zh/about/sponsor' },
  23. { text: '社区', link: '/zh/about/contact' },
  24. { text: '谁在使用 Xmake?', link: '/zh/about/who_is_using_xmake' },
  25. ]
  26. },
  27. {
  28. text: '下一步',
  29. items: [
  30. { text: '文档', link: '/zh/guide/introduction' }
  31. ]
  32. }
  33. ],
  34. '/zh/blog/': [
  35. {
  36. text: '博客',
  37. items: [
  38. { text: '返回首页', link: '/zh/' }
  39. ]
  40. },
  41. {
  42. text: '下一步',
  43. items: [
  44. { text: '文档', link: '/zh/guide/introduction' }
  45. ]
  46. }
  47. ],
  48. ...postsSidebar(),
  49. },
  50. editLink: {
  51. pattern: 'https://github.com/xmake-io/xmake-docs/edit/master/docs/:path',
  52. text: '在 GitHub 上编辑此页面'
  53. },
  54. docFooter: {
  55. prev: '上一页',
  56. next: '下一页'
  57. },
  58. lastUpdated: {
  59. text: '最后更新于'
  60. },
  61. outline: {
  62. label: '页面导航'
  63. },
  64. notFound: {
  65. title: '页面未找到',
  66. quote:
  67. '但如果你不改变方向,并且继续寻找,你可能最终会到达你所前往的地方。',
  68. linkLabel: '前往首页',
  69. linkText: '带我回首页'
  70. },
  71. langMenuLabel: '多语言',
  72. returnToTopLabel: '回到顶部',
  73. sidebarMenuLabel: '菜单',
  74. darkModeSwitchLabel: '主题',
  75. lightModeSwitchTitle: '切换到浅色模式',
  76. darkModeSwitchTitle: '切换到深色模式',
  77. skipToContentLabel: '跳转到内容'
  78. }
  79. })
  80. function searchOptions(): Partial<DefaultTheme.AlgoliaSearchOptions> {
  81. return {
  82. placeholder: '搜索文档',
  83. translations: {
  84. button: {
  85. buttonText: '搜索文档',
  86. buttonAriaLabel: '搜索文档'
  87. },
  88. modal: {
  89. searchBox: {
  90. resetButtonTitle: '清除查询条件',
  91. resetButtonAriaLabel: '清除查询条件',
  92. cancelButtonText: '取消',
  93. cancelButtonAriaLabel: '取消'
  94. },
  95. startScreen: {
  96. recentSearchesTitle: '搜索历史',
  97. noRecentSearchesText: '没有搜索历史',
  98. saveRecentSearchButtonTitle: '保存至搜索历史',
  99. removeRecentSearchButtonTitle: '从搜索历史中移除',
  100. favoriteSearchesTitle: '收藏',
  101. removeFavoriteSearchButtonTitle: '从收藏中移除'
  102. },
  103. errorScreen: {
  104. titleText: '无法获取结果',
  105. helpText: '你可能需要检查你的网络连接'
  106. },
  107. footer: {
  108. selectText: '选择',
  109. navigateText: '切换',
  110. closeText: '关闭',
  111. searchByText: '搜索提供者'
  112. },
  113. noResultsScreen: {
  114. noResultsText: '无法找到相关结果',
  115. suggestedQueryText: '你可以尝试查询',
  116. reportMissingResultsText: '你认为该查询应该有结果?',
  117. reportMissingResultsLinkText: '点击反馈'
  118. }
  119. }
  120. }
  121. }
  122. }
  123. function nav(): DefaultTheme.NavItem[] {
  124. return [
  125. {
  126. text: '文档',
  127. activeMatch: `^/(guide|style-guide|cookbook|examples)/`,
  128. items: [
  129. { text: '使用指南', link: '/zh/guide/introduction', activeMatch: '/zh/guide/' },
  130. { text: '快速上手', link: '/zh/guide/quick-start' },
  131. { text: '示例', link: '/zh/examples/cpp/basic', activeMatch: '/zh/examples/' },
  132. { text: 'API 手册', link: '/zh/api/description/specification', activeMatch: '/zh/api/' }
  133. ]
  134. },
  135. {
  136. text: '博客',
  137. link: '/zh/blog/',
  138. activeMatch: '/zh/blog/'
  139. },
  140. {
  141. text: '生态系统',
  142. items: [
  143. {
  144. text: '资源',
  145. items: [
  146. { text: 'Xmake 包仓库', link: 'https://xmake.microblock.cc/' }
  147. ]
  148. },
  149. {
  150. text: '帮助',
  151. items: [
  152. { text: '社区', link: '/zh/about/contact' },
  153. { text: '问题反馈', link: 'https://github.com/xmake-io/xmake/issues' },
  154. { text: '谁在使用 Xmake?', link: '/zh/about/who_is_using_xmake' }
  155. ]
  156. },
  157. {
  158. text: '其他',
  159. items: [
  160. { text: '实验楼课程', link: '/zh/about/course' },
  161. { text: '周边物品', link: '/zh/about/peripheral_items' }
  162. ]
  163. }
  164. ]
  165. },
  166. { text: '赞助', link: '/zh/about/sponsor' }
  167. ]
  168. }
  169. function postsSidebar(): Record<string, DefaultTheme.SidebarItem[]> {
  170. const sidebar: Record<string, DefaultTheme.SidebarItem[]> = {}
  171. for (let i = 0; i < posts.length; i++) {
  172. const post = posts[i]
  173. const next = i > 0 ? posts[i - 1] : null
  174. const prev = i < posts.length - 1 ? posts[i + 1] : null
  175. const items = []
  176. if (next) {
  177. items.push({ text: '上一篇', link: next.url })
  178. }
  179. if (prev) {
  180. items.push({ text: '下一篇', link: prev.url })
  181. }
  182. items.push({
  183. text: '下一步',
  184. items: [
  185. { text: '文档', link: '/zh/guide/introduction' }
  186. ]
  187. })
  188. sidebar[post.url + '.html'] = items
  189. sidebar[post.url] = items
  190. }
  191. return sidebar
  192. }
  193. function guideSidebar(): DefaultTheme.SidebarItem[] {
  194. return [
  195. {
  196. text: '开始',
  197. collapsed: false,
  198. items: [
  199. { text: '简介', link: 'introduction' },
  200. { text: '快速上手', link: 'quick-start' }
  201. ]
  202. },
  203. {
  204. text: '基础命令',
  205. collapsed: false,
  206. items: [
  207. { text: '创建工程', link: 'basic-commands/create-project' },
  208. { text: '编译配置', link: 'basic-commands/build-configuration' },
  209. { text: '构建目标', link: 'basic-commands/build-targets' },
  210. { text: '运行目标', link: 'basic-commands/run-targets' },
  211. { text: '安装卸载', link: 'basic-commands/install-and-uninstall' },
  212. { text: '打包程序', link: 'basic-commands/pack-programs' },
  213. { text: '交叉编译', link: 'basic-commands/cross-compilation' },
  214. { text: '切换工具链', link: 'basic-commands/switch-toolchains' },
  215. ]
  216. },
  217. {
  218. text: '工程配置',
  219. collapsed: false,
  220. items: [
  221. { text: '语法描述', link: 'project-configuration/syntax-description' },
  222. { text: '配置目标', link: 'project-configuration/configure-targets' },
  223. { text: '定义选项', link: 'project-configuration/define-options' },
  224. { text: '添加依赖包', link: 'project-configuration/add-packages' },
  225. { text: '多级目录配置', link: 'project-configuration/multi-level-directories' },
  226. { text: '工具链配置', link: 'project-configuration/toolchain-configuration' },
  227. { text: '命名空间隔离', link: 'project-configuration/namespace-isolation' },
  228. { text: '自定义规则', link: 'project-configuration/custom-rule' },
  229. { text: '插件和任务', link: 'project-configuration/plugin-and-task' },
  230. ]
  231. },
  232. {
  233. text: '包依赖管理',
  234. collapsed: false,
  235. items: [
  236. {
  237. text: '使用远程包',
  238. collapsed: true,
  239. items: [
  240. { text: '使用官方包', link: 'package-management/using-official-packages' },
  241. { text: '使用第三方包', link: 'package-management/using-third-party-packages' },
  242. { text: '在 CMake 中使用包', link: 'package-management/using-packages-in-cmake' },
  243. { text: '分发包到仓库', link: 'package-management/package-distribution' },
  244. ]
  245. },
  246. { text: '使用本地包', link: 'package-management/using-local-packages' },
  247. { text: '使用系统包', link: 'package-management/using-system-packages' },
  248. { text: '使用源码包', link: 'package-management/using-source-code-packages' },
  249. { text: '分发私有库', link: 'package-management/distribute-private-libraries' },
  250. { text: '网络优化', link: 'package-management/network-optimization' },
  251. {
  252. text: 'CLI',
  253. collapsed: true,
  254. items: [
  255. { text: '工程内包管理', link: 'package-management/package-management-in-project' },
  256. { text: '仓库管理', link: 'package-management/repository-management' },
  257. { text: 'Xrepo CLI', link: 'package-management/xrepo-cli' },
  258. ]
  259. },
  260. ]
  261. },
  262. {
  263. text: '扩展',
  264. collapsed: false,
  265. items: [
  266. { text: '插件开发', link: 'extensions/plugin-development' },
  267. { text: '内置插件', link: 'extensions/builtin-plugins' },
  268. { text: 'IDE 集成插件', link: 'extensions/ide-integration-plugins' },
  269. { text: '主题风格', link: 'extensions/theme-style' },
  270. ]
  271. },
  272. {
  273. text: '最佳实践',
  274. collapsed: false,
  275. items: [
  276. { text: '常见问题', link: 'best-practices/faq' },
  277. { text: '性能优化', link: 'best-practices/performance' },
  278. { text: 'AI 问答优化', link: 'best-practices/ai-qa-optimization' },
  279. ]
  280. },
  281. {
  282. text: '进阶主题',
  283. collapsed: false,
  284. items: [
  285. { text: '远程编译', link: 'extras/remote-compilation' },
  286. { text: '分布式编译', link: 'extras/distributed-compilation' },
  287. { text: '编译缓存加速', link: 'extras/build-cache' },
  288. { text: 'Unity 编译加速', link: 'extras/unity-build' },
  289. { text: '自动扫描源码', link: 'extras/autoscan-sourcecode' },
  290. { text: '尝试构建第三方源码', link: 'extras/trybuild-3rd-sourcecode' },
  291. { text: '环境变量', link: 'extras/environment-variables' },
  292. ]
  293. },
  294. {
  295. text: '下一步',
  296. collapsed: false,
  297. items: [
  298. { text: 'API 手册', link: '../api/description/specification' },
  299. { text: '示例', link: '../examples/cpp/basic' },
  300. ]
  301. }
  302. ]
  303. }
  304. function descriptionApiSidebar(): DefaultTheme.SidebarItem[] {
  305. return [
  306. {
  307. text: '描述域 API',
  308. collapsed: false,
  309. items: [
  310. { text: '接口规范', link: 'specification' },
  311. { text: '全局接口', link: 'global-interfaces' },
  312. { text: '条件判断', link: 'conditions' },
  313. { text: '辅助接口', link: 'helper-interfaces' },
  314. { text: '工程目标', link: 'project-target' },
  315. { text: '配置选项', link: 'configuration-option' },
  316. { text: '插件任务', link: 'plugin-and-task' },
  317. { text: '自定义规则', link: 'custom-rule' },
  318. { text: '自定义工具链', link: 'custom-toolchain' },
  319. { text: '包依赖', link: 'package-dependencies' },
  320. { text: '内置变量', link: 'builtin-variables' },
  321. { text: '内置规则', link: 'builtin-rules' },
  322. { text: '内置策略', link: 'builtin-policies' },
  323. { text: 'XPack 打包接口', link: 'xpack-interfaces' },
  324. { text: 'XPack 组件接口', link: 'xpack-component-interfaces' },
  325. ]
  326. },
  327. {
  328. text: '下一步',
  329. collapsed: false,
  330. items: [
  331. { text: '脚本域 API', link: '../scripts/target-instance' },
  332. { text: '使用指南', link: '../../guide/introduction' },
  333. { text: '示例', link: '../../examples/cpp/basic' },
  334. ]
  335. }
  336. ]
  337. }
  338. function scriptsApiSidebar(): DefaultTheme.SidebarItem[] {
  339. return [
  340. {
  341. text: '脚本域 API',
  342. collapsed: false,
  343. items: [
  344. { text: '目标实例', link: 'target-instance' },
  345. { text: '选项实例', link: 'option-instance' },
  346. { text: '包实例', link: 'package-instance' },
  347. ]
  348. },
  349. {
  350. text: '内置模块',
  351. collapsed: true,
  352. items: builtinModulesApiSidebarItems()
  353. },
  354. {
  355. text: '扩展模块',
  356. collapsed: false,
  357. items: extensionModulesApiSidebarItems()
  358. },
  359. { text: '原生模块', link: 'native-modules' },
  360. {
  361. text: '下一步',
  362. collapsed: false,
  363. items: [
  364. { text: '描述域 API', link: '../description/specification' },
  365. { text: '使用指南', link: '../../guide/introduction' },
  366. { text: '示例', link: '../../examples/cpp/basic' },
  367. ]
  368. }
  369. ]
  370. }
  371. function examplesSidebar(): DefaultTheme.SidebarItem[] {
  372. return [
  373. {
  374. text: 'C/C++',
  375. collapsed: false,
  376. items: [
  377. { text: '基础程序', link: 'cpp/basic' },
  378. { text: 'C++ 模块', link: 'cpp/cxx-modules' },
  379. { text: 'Wasm 程序', link: 'cpp/wasm' },
  380. { text: 'WDK 程序', link: 'cpp/wdk' },
  381. { text: 'Protobuf 程序', link: 'cpp/protobuf' },
  382. { text: 'OpenMP 程序', link: 'cpp/openmp' },
  383. { text: 'Linux Bpf 程序', link: 'cpp/linux-bpf' },
  384. { text: 'Linux 内核驱动模块', link: 'cpp/linux-driver-module' },
  385. { text: 'ASN.1 程序', link: 'cpp/asn1' },
  386. { text: 'CppFront 程序', link: 'cpp/cppfront' },
  387. { text: 'Cosmocc 程序', link: 'cpp/cosmocc' },
  388. { text: '合并静态库', link: 'cpp/merge-static-libraries' },
  389. { text: 'Bin2c/Bin2obj 程序', link: 'cpp/bin2c-obj' },
  390. { text: '包管理', link: 'cpp/packages' },
  391. { text: 'XPack 打包程序', link: 'cpp/xpack' },
  392. ]
  393. },
  394. {
  395. text: 'Xmake 配置',
  396. collapsed: true,
  397. items: [
  398. { text: '多级目录配置', link: 'configuration/multi_level_directories' },
  399. { text: '命名空间隔离', link: 'configuration/namespace_isolation' },
  400. { text: '自定义工具链', link: 'configuration/custom_toolchain' },
  401. { text: '远程工具链', link: 'configuration/remote_toolchain' },
  402. { text: 'Unity 编译加速', link: 'configuration/unity_build' },
  403. { text: '自定义规则', link: 'configuration/custom_rule' },
  404. { text: '自定义模块', link: 'configuration/custom_module' },
  405. { text: '自定义描述域 API', link: 'configuration/custom_scope_api' },
  406. { text: '配置文件生成', link: 'configuration/add_configfiles' },
  407. { text: '自动代码生成', link: 'configuration/autogen' },
  408. ]
  409. },
  410. {
  411. text: '图形与音视频',
  412. collapsed: true,
  413. items: [
  414. { text: 'OpenGL 程序', link: 'cpp/graphics/opengl' },
  415. { text: 'Vulkan 程序', link: 'cpp/graphics/vulkan' },
  416. { text: 'SDL2 程序', link: 'cpp/graphics/sdl' },
  417. { text: 'Raylib 程序', link: 'cpp/graphics/raylib' },
  418. { text: 'ImGui 程序', link: 'cpp/graphics/imgui' },
  419. { text: 'Qt 程序', link: 'cpp/graphics/qt' },
  420. { text: 'WinSDK 程序', link: 'cpp/graphics/winsdk' },
  421. { text: 'MFC 程序', link: 'cpp/graphics/mfc' },
  422. { text: 'Android Native App', link: 'cpp/graphics/android' },
  423. { text: 'GLSL/HLSL 转 SPIR-V', link: 'cpp/graphics/glsl2spv' },
  424. { text: 'Mac App 程序', link: 'cpp/graphics/mac_app' },
  425. { text: 'iOS App 程序', link: 'cpp/graphics/ios_app' },
  426. { text: 'Metal App 程序', link: 'cpp/graphics/metal_app' },
  427. { text: 'Linux Framebuffer 程序', link: 'cpp/graphics/linux_framebuffer' },
  428. { text: 'TUI 程序', link: 'cpp/graphics/tui' },
  429. { text: 'Audio 程序', link: 'cpp/graphics/audio' },
  430. ]
  431. },
  432. {
  433. text: '语言绑定模块',
  434. collapsed: true,
  435. items: [
  436. { text: 'Swig 模块', link: 'bindings/swig' },
  437. { text: 'Lua 模块', link: 'bindings/lua-module' },
  438. { text: 'Python 模块', link: 'bindings/python-module' },
  439. { text: 'NodeJS 模块', link: 'bindings/nodejs-module' },
  440. ]
  441. },
  442. {
  443. text: '嵌入式程序',
  444. collapsed: true,
  445. items: [
  446. { text: 'Keil/MDK 程序', link: 'embed/keil-mdk' },
  447. { text: 'Keil/C51 程序', link: 'embed/keil-c51' },
  448. { text: 'Verilog 仿真程序', link: 'embed/verilog' },
  449. ]
  450. },
  451. {
  452. text: '其他语言',
  453. collapsed: true,
  454. items: [
  455. { text: 'ObjC 程序', link: 'other-languages/objc' },
  456. { text: 'Cuda 程序', link: 'other-languages/cuda' },
  457. { text: 'Lex/Yacc 程序', link: 'other-languages/lex-yacc' },
  458. { text: 'Fortran 程序', link: 'other-languages/fortran' },
  459. { text: 'Golang 程序', link: 'other-languages/golang' },
  460. { text: 'Dlang 程序', link: 'other-languages/dlang' },
  461. { text: 'Rust 程序', link: 'other-languages/rust' },
  462. { text: 'Swift 程序', link: 'other-languages/swift' },
  463. { text: 'Zig 程序', link: 'other-languages/zig' },
  464. { text: 'Vala 程序', link: 'other-languages/vala' },
  465. { text: 'Pascal 程序', link: 'other-languages/pascal' },
  466. { text: 'Nim 程序', link: 'other-languages/nim' },
  467. ]
  468. },
  469. {
  470. text: '下一步',
  471. collapsed: false,
  472. items: [
  473. { text: 'API 手册', link: '../api/description/specification' },
  474. { text: '使用指南', link: '../guide/introduction' },
  475. ]
  476. }
  477. ]
  478. }