config.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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/blog-data.js'
  5. const require = createRequire(import.meta.url)
  6. const pkg = require('vitepress/package.json')
  7. export default defineAdditionalConfig({
  8. lang: 'en-US',
  9. description: "A cross-platform build utility based on Lua",
  10. themeConfig: {
  11. nav: nav(),
  12. sidebar: {
  13. '/guide/': { base: '/guide/', items: guideSidebar() },
  14. '/api/description/': { base: '/api/description/', items: descriptionApiSidebar() },
  15. '/api/scripts/': { base: '/api/scripts/', items: scriptsApiSidebar() },
  16. '/examples/': { base: '/examples/', items: examplesSidebar() },
  17. '/about/': [
  18. {
  19. text: 'About',
  20. items: [
  21. { text: 'Sponsor', link: '/about/sponsor' },
  22. { text: 'Contact', link: '/about/contact' },
  23. { text: 'Who is using Xmake?', link: '/about/who_is_using_xmake' },
  24. ]
  25. },
  26. {
  27. text: 'Next Steps',
  28. items: [
  29. { text: 'Documentation', link: '/guide/introduction' }
  30. ]
  31. }
  32. ],
  33. '/blog/': [
  34. {
  35. text: 'Blog',
  36. items: [
  37. { text: 'Return to Home', link: '/' }
  38. ]
  39. },
  40. {
  41. text: 'Next Steps',
  42. items: [
  43. { text: 'Documentation', link: '/guide/introduction' }
  44. ]
  45. }
  46. ],
  47. ...postsSidebar(),
  48. },
  49. editLink: {
  50. pattern: 'https://github.com/xmake-io/xmake-docs/edit/master/docs/:path',
  51. text: 'Edit this page on GitHub'
  52. }
  53. }
  54. })
  55. function nav(): DefaultTheme.NavItem[] {
  56. return [
  57. {
  58. text: 'Docs',
  59. activeMatch: `^/(guide|style-guide|cookbook|examples)/`,
  60. items: [
  61. { text: 'Guide', link: '/guide/introduction', activeMatch: '/guide/' },
  62. { text: 'Quick Start', link: '/guide/quick-start' },
  63. { text: 'Examples', link: '/examples/cpp/basic', activeMatch: '/examples/' },
  64. { text: 'API Reference', link: '/api/description/specification', activeMatch: '/api/' }
  65. ]
  66. },
  67. {
  68. text: 'Blog',
  69. link: '/blog/',
  70. activeMatch: '/blog/'
  71. },
  72. {
  73. text: 'Ecosystem',
  74. items: [
  75. {
  76. text: 'Resources',
  77. items: [
  78. { text: 'Xmake Packages', link: 'https://xmake.microblock.cc/' }
  79. ]
  80. },
  81. {
  82. text: 'Help',
  83. items: [
  84. { text: 'Community', link: '/about/contact' },
  85. { text: 'Feedback', link: 'https://github.com/xmake-io/xmake/issues' },
  86. { text: 'Who is using Xmake?', link: '/about/who_is_using_xmake' }
  87. ]
  88. }
  89. ]
  90. },
  91. { text: 'Sponsor', link: '/about/sponsor' }
  92. ]
  93. }
  94. function postsSidebar(): Record<string, DefaultTheme.SidebarItem[]> {
  95. const sidebar: Record<string, DefaultTheme.SidebarItem[]> = {}
  96. for (let i = 0; i < posts.length; i++) {
  97. const post = posts[i]
  98. const next = i > 0 ? posts[i - 1] : null
  99. const prev = i < posts.length - 1 ? posts[i + 1] : null
  100. const items = []
  101. if (next) {
  102. items.push({ text: 'Previous Post', link: next.url })
  103. }
  104. if (prev) {
  105. items.push({ text: 'Next Post', link: prev.url })
  106. }
  107. items.push({
  108. text: 'Next Steps',
  109. items: [
  110. { text: 'Documentation', link: '/guide/introduction' }
  111. ]
  112. })
  113. sidebar[post.url + '.html'] = items
  114. sidebar[post.url] = items
  115. }
  116. return sidebar
  117. }
  118. function guideSidebar(): DefaultTheme.SidebarItem[] {
  119. return [
  120. {
  121. text: 'Getting Started',
  122. collapsed: false,
  123. items: [
  124. { text: 'Introduction', link: 'introduction' },
  125. { text: 'Quick Start', link: 'quick-start' },
  126. ]
  127. },
  128. {
  129. text: 'Basic Commands',
  130. collapsed: false,
  131. items: [
  132. { text: 'Create Project', link: 'basic-commands/create-project' },
  133. { text: 'Build Configuration', link: 'basic-commands/build-configuration' },
  134. { text: 'Build Targets', link: 'basic-commands/build-targets' },
  135. { text: 'Run Targets', link: 'basic-commands/run-targets' },
  136. { text: 'Install and Uninstall', link: 'basic-commands/install-and-uninstall' },
  137. { text: 'Pack Programs', link: 'basic-commands/pack-programs' },
  138. { text: 'Cross Compilation', link: 'basic-commands/cross-compilation' },
  139. { text: 'Switch Toolchains', link: 'basic-commands/switch-toolchains' },
  140. ]
  141. },
  142. {
  143. text: 'Project Configuration',
  144. collapsed: false,
  145. items: [
  146. { text: 'Syntax Description', link: 'project-configuration/syntax-description' },
  147. { text: 'Configure Targets', link: 'project-configuration/configure-targets' },
  148. { text: 'Define Options', link: 'project-configuration/define-options' },
  149. { text: 'Add Packages', link: 'project-configuration/add-packages' },
  150. { text: 'Multi-level Directories', link: 'project-configuration/multi-level-directories' },
  151. { text: 'Toolchain Configuration', link: 'project-configuration/toolchain-configuration' },
  152. { text: 'Namespace Isolation', link: 'project-configuration/namespace-isolation' },
  153. { text: 'Custom Rules', link: 'project-configuration/custom-rule' },
  154. { text: 'Plugins and Tasks', link: 'project-configuration/plugin-and-task' },
  155. ]
  156. },
  157. {
  158. text: 'Package Management',
  159. collapsed: false,
  160. items: [
  161. {
  162. text: 'Using Remote Packages',
  163. collapsed: true,
  164. items: [
  165. { text: 'Using Official Packages', link: 'package-management/using-official-packages' },
  166. { text: 'Using Third-party Packages', link: 'package-management/using-third-party-packages' },
  167. { text: 'Using Packages in CMake', link: 'package-management/using-packages-in-cmake' },
  168. { text: 'Package Distribution', link: 'package-management/package-distribution' },
  169. ]
  170. },
  171. { text: 'Using Local Packages', link: 'package-management/using-local-packages' },
  172. { text: 'Using System Packages', link: 'package-management/using-system-packages' },
  173. { text: 'Using Sourcecode Packages', link: 'package-management/using-source-code-packages' },
  174. { text: 'Distribute Private Libraries', link: 'package-management/distribute-private-libraries' },
  175. { text: 'Network Optimization', link: 'package-management/network-optimization' },
  176. {
  177. text: 'CLI',
  178. collapsed: true,
  179. items: [
  180. { text: 'Package Management in Project', link: 'package-management/package-management-in-project' },
  181. { text: 'Repository Management', link: 'package-management/repository-management' },
  182. { text: 'Xrepo CLI', link: 'package-management/xrepo-cli' },
  183. ]
  184. },
  185. ]
  186. },
  187. {
  188. text: 'Extensions',
  189. collapsed: false,
  190. items: [
  191. { text: 'Plugin Development', link: 'extensions/plugin-development' },
  192. { text: 'Builtin Plugins', link: 'extensions/builtin-plugins' },
  193. { text: 'IDE Integration Plugins', link: 'extensions/ide-integration-plugins' },
  194. { text: 'Theme Style', link: 'extensions/theme-style' },
  195. ]
  196. },
  197. {
  198. text: 'Best Practices',
  199. collapsed: false,
  200. items: [
  201. { text: 'FAQ', link: 'best-practices/faq' },
  202. { text: 'Performance', link: 'best-practices/performance' },
  203. { text: 'AI Q&A Optimization', link: 'best-practices/ai-qa-optimization' },
  204. ]
  205. },
  206. {
  207. text: 'Extra Topics',
  208. collapsed: false,
  209. items: [
  210. { text: 'Remote Compilation', link: 'extras/remote-compilation' },
  211. { text: 'Distributed Compilation', link: 'extras/distributed-compilation' },
  212. { text: 'Build Cache Acceleration', link: 'extras/build-cache' },
  213. { text: 'Unity Build Acceleration', link: 'extras/unity-build' },
  214. { text: 'Auto-scan Sourcecode', link: 'extras/autoscan-sourcecode' },
  215. { text: 'Try Build 3rd Sourcecode', link: 'extras/trybuild-3rd-sourcecode' },
  216. { text: 'Envirnoment Variables', link: 'extras/environment-variables' },
  217. ]
  218. },
  219. {
  220. text: 'Next Steps',
  221. collapsed: false,
  222. items: [
  223. { text: 'API Reference', link: '../api/description/specification' },
  224. { text: 'Examples', link: '../examples/cpp/basic' },
  225. ]
  226. }
  227. ]
  228. }
  229. function descriptionApiSidebar(): DefaultTheme.SidebarItem[] {
  230. return [
  231. {
  232. text: 'Description API',
  233. collapsed: false,
  234. items: [
  235. { text: 'Specification', link: 'specification' },
  236. { text: 'Conditions', link: 'conditions' },
  237. { text: 'Global Interfaces', link: 'global-interfaces' },
  238. { text: 'Helper Interfaces', link: 'helper-interfaces' },
  239. { text: 'Project Targets', link: 'project-target' },
  240. { text: 'Configuration Option', link: 'configuration-option' },
  241. { text: 'Plugin and Task', link: 'plugin-and-task' },
  242. { text: 'Custom Rule', link: 'custom-rule' },
  243. { text: 'Custom Toolchain', link: 'custom-toolchain' },
  244. { text: 'Package Dependencies', link: 'package-dependencies' },
  245. { text: 'Builtin Variables', link: 'builtin-variables' },
  246. { text: 'Builtin Rules', link: 'builtin-rules' },
  247. { text: 'Builtin Policies', link: 'builtin-policies' },
  248. { text: 'XPack Interfaces', link: 'xpack-interfaces' },
  249. { text: 'XPack Component Interfaces', link: 'xpack-component-interfaces' },
  250. ]
  251. },
  252. {
  253. text: 'Next Steps',
  254. collapsed: false,
  255. items: [
  256. { text: 'Scripts API', link: '../scripts/target-instance' },
  257. { text: 'Guide', link: '../../guide/introduction' },
  258. { text: 'Examples', link: '../../examples/cpp/basic' },
  259. ]
  260. }
  261. ]
  262. }
  263. function scriptsApiSidebar(): DefaultTheme.SidebarItem[] {
  264. return [
  265. {
  266. text: 'Scripts API',
  267. collapsed: false,
  268. items: [
  269. { text: 'Target Instance', link: 'target-instance' },
  270. { text: 'Option Instance', link: 'option-instance' },
  271. { text: 'Package Instance', link: 'package-instance' },
  272. ]
  273. },
  274. {
  275. text: 'Builtin Modules',
  276. collapsed: true,
  277. items: builtinModulesApiSidebarItems()
  278. },
  279. {
  280. text: 'Extension Modules',
  281. collapsed: false,
  282. items: extensionModulesApiSidebarItems()
  283. },
  284. { text: 'Native Modules', link: 'native-modules' },
  285. {
  286. text: 'Next Steps',
  287. collapsed: false,
  288. items: [
  289. { text: 'Description API', link: '../description/specification' },
  290. { text: 'Guide', link: '../../guide/introduction' },
  291. { text: 'Examples', link: '../../examples/cpp/basic' },
  292. ]
  293. }
  294. ]
  295. }
  296. function examplesSidebar(): DefaultTheme.SidebarItem[] {
  297. return [
  298. {
  299. text: 'C/C++',
  300. collapsed: false,
  301. items: [
  302. { text: 'Basic Programs', link: 'cpp/basic' },
  303. { text: 'C++ Modules', link: 'cpp/cxx-modules' },
  304. { text: 'Wasm Programs', link: 'cpp/wasm' },
  305. { text: 'WDK Programs', link: 'cpp/wdk' },
  306. { text: 'Protobuf Programs', link: 'cpp/protobuf' },
  307. { text: 'OpenMP Programs', link: 'cpp/openmp' },
  308. { text: 'Linux Bpf Programs', link: 'cpp/linux-bpf' },
  309. { text: 'Linux Kernel Driver Module', link: 'cpp/linux-driver-module' },
  310. { text: 'ASN.1 Programs', link: 'cpp/asn1' },
  311. { text: 'CppFront Programs', link: 'cpp/cppfront' },
  312. { text: 'Cosmocc Programs', link: 'cpp/cosmocc' },
  313. { text: 'Merge Static Libraries', link: 'cpp/merge-static-libraries' },
  314. { text: 'Bin2c/Bin2obj', link: 'cpp/bin2c-obj' },
  315. { text: 'Package Management', link: 'cpp/packages' },
  316. { text: 'XPack Packaging', link: 'cpp/xpack' },
  317. ]
  318. },
  319. {
  320. text: 'Xmake Configuration',
  321. collapsed: true,
  322. items: [
  323. { text: 'Multi-level Directories', link: 'configuration/multi_level_directories' },
  324. { text: 'Namespace Isolation', link: 'configuration/namespace_isolation' },
  325. { text: 'Custom Toolchain', link: 'configuration/custom_toolchain' },
  326. { text: 'Remote Toolchain', link: 'configuration/remote_toolchain' },
  327. { text: 'Unity Build', link: 'configuration/unity_build' },
  328. { text: 'Custom Rule', link: 'configuration/custom_rule' },
  329. { text: 'Custom Module', link: 'configuration/custom_module' },
  330. { text: 'Custom Scope API', link: 'configuration/custom_scope_api' },
  331. { text: 'Config Header Generation', link: 'configuration/add_configfiles' },
  332. { text: 'Autogen Programs', link: 'configuration/autogen' },
  333. ]
  334. },
  335. {
  336. text: 'Graphics & Audio',
  337. collapsed: true,
  338. items: [
  339. { text: 'OpenGL', link: 'cpp/graphics/opengl' },
  340. { text: 'Vulkan', link: 'cpp/graphics/vulkan' },
  341. { text: 'SDL2', link: 'cpp/graphics/sdl' },
  342. { text: 'Raylib', link: 'cpp/graphics/raylib' },
  343. { text: 'ImGui', link: 'cpp/graphics/imgui' },
  344. { text: 'Qt Programs', link: 'cpp/graphics/qt' },
  345. { text: 'WinSDK Programs', link: 'cpp/graphics/winsdk' },
  346. { text: 'MFC Programs', link: 'cpp/graphics/mfc' },
  347. { text: 'Android Native App', link: 'cpp/graphics/android' },
  348. { text: 'GLSL/HLSL to SPIR-V', link: 'cpp/graphics/glsl2spv' },
  349. { text: 'Mac App', link: 'cpp/graphics/mac_app' },
  350. { text: 'iOS App', link: 'cpp/graphics/ios_app' },
  351. { text: 'Metal App', link: 'cpp/graphics/metal_app' },
  352. { text: 'Linux Framebuffer Programs', link: 'cpp/graphics/linux_framebuffer' },
  353. { text: 'TUI Programs', link: 'cpp/graphics/tui' },
  354. { text: 'Audio Programs', link: 'cpp/graphics/audio' },
  355. ]
  356. },
  357. {
  358. text: 'Bindings Programs',
  359. collapsed: true,
  360. items: [
  361. { text: 'Swig Modules', link: 'bindings/swig' },
  362. { text: 'Lua Modules', link: 'bindings/lua-module' },
  363. { text: 'Python Modules', link: 'bindings/python-module' },
  364. { text: 'NodeJS Modules', link: 'bindings/nodejs-module' },
  365. ]
  366. },
  367. {
  368. text: 'Embed Programs',
  369. collapsed: true,
  370. items: [
  371. { text: 'Keil/MDK Embed Programs', link: 'embed/keil-mdk' },
  372. { text: 'Keil/C51 Embed Programs', link: 'embed/keil-c51' },
  373. { text: 'Verilog Programs', link: 'embed/verilog' },
  374. ]
  375. },
  376. {
  377. text: 'Other Languages',
  378. collapsed: true,
  379. items: [
  380. { text: 'ObjC Programs', link: 'other-languages/objc' },
  381. { text: 'Cuda Programs', link: 'other-languages/cuda' },
  382. { text: 'Lex/Yacc Programs', link: 'other-languages/lex-yacc' },
  383. { text: 'Fortran Programs', link: 'other-languages/fortran' },
  384. { text: 'Golang Programs', link: 'other-languages/golang' },
  385. { text: 'Dlang Programs', link: 'other-languages/dlang' },
  386. { text: 'Rust Programs', link: 'other-languages/rust' },
  387. { text: 'Swift Programs', link: 'other-languages/swift' },
  388. { text: 'Zig Programs', link: 'other-languages/zig' },
  389. { text: 'Vala Programs', link: 'other-languages/vala' },
  390. { text: 'Pascal Programs', link: 'other-languages/pascal' },
  391. { text: 'Nim Programs', link: 'other-languages/nim' },
  392. { text: 'Verilog Programs', link: 'other-languages/verilog' },
  393. ]
  394. },
  395. {
  396. text: 'Next Steps',
  397. collapsed: false,
  398. items: [
  399. { text: 'API Reference', link: '../api/description/specification' },
  400. { text: 'Guide', link: '../guide/introduction' },
  401. ]
  402. }
  403. ]
  404. }