config.mts 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. import { defineConfig } from 'vitepress'
  2. import path from 'path'
  3. import menuConfig from './menuConfig'
  4. import vueJsx from '@vitejs/plugin-vue-jsx'
  5. import { withMermaid } from 'vitepress-plugin-mermaid'
  6. // import AuthMid from './plugins/casdoor/mid'
  7. // import SseMid from './plugins/SSE/server'
  8. // import { watch } from 'fs'
  9. const fileAndStyles: Record<string, string> = {}
  10. const BaseUrl = '/fwhwiki/'
  11. process.env.BASE_URL = BaseUrl
  12. const MalinePrefix = `${BaseUrl}waline`
  13. // https://vitepress.dev/reference/site-config
  14. export default defineConfig(
  15. withMermaid({
  16. base: BaseUrl,
  17. lang: 'zh-CN',
  18. title: 'FranklinWH Wiki',
  19. description: 'FranklinWH Wiki',
  20. head: [
  21. ['link', { rel: 'icon', type: 'image/svg+xml', href: BaseUrl + 'favicon.svg' }]
  22. ],
  23. themeConfig: {
  24. logo: {
  25. src: '/F_logo.svg',
  26. width: 24,
  27. height: 24
  28. },
  29. // https://vitepress.dev/reference/default-theme-config
  30. ...menuConfig,
  31. outline: {
  32. level: 'deep',
  33. label: '页面导航'
  34. },
  35. search: {
  36. provider: 'local',
  37. options: {
  38. translations: {
  39. button: {
  40. buttonText: '搜索文档',
  41. buttonAriaLabel: '搜索文档'
  42. },
  43. modal: {
  44. noResultsText: '无法找到相关结果',
  45. resetButtonTitle: '清除查询条件',
  46. footer: {
  47. selectText: '选择',
  48. navigateText: '切换',
  49. closeText: '关闭'
  50. }
  51. }
  52. },
  53. locales: {
  54. zh: {
  55. label: '简体中文',
  56. lang: 'zh-CN',
  57. link: '/', // 默认语言链接
  58. translations: {
  59. button: {
  60. buttonText: '搜索文档',
  61. buttonAriaLabel: '搜索文档'
  62. },
  63. modal: {
  64. noResultsText: '无法找到相关结果',
  65. resetButtonTitle: '清除查询条件',
  66. footer: {
  67. selectText: '选择',
  68. navigateText: '切换'
  69. }
  70. }
  71. }
  72. },
  73. en: {
  74. label: 'English',
  75. lang: 'en-US',
  76. link: '/en/'
  77. }
  78. }
  79. }
  80. }
  81. },
  82. markdown: {
  83. // markdown-it-anchor 的选项
  84. // https://github.com/valeriangalliat/markdown-it-anchor#usage
  85. container: {
  86. tipLabel: ':bell: 提示',
  87. warningLabel: ':warning: 警告',
  88. dangerLabel: ':no_entry: 危险',
  89. infoLabel: ':receipt: 信息',
  90. detailsLabel: '详细信息'
  91. },
  92. lineNumbers: true, // 代码块启用行号
  93. math: true, // 启用数学方程
  94. image: {
  95. lazyLoading: true // 为所有图片启用懒加载
  96. }
  97. },
  98. // optionally, you can pass MermaidConfig
  99. mermaid: {
  100. // refer https://mermaid.js.org/config/setup/modules/mermaidAPI.html#mermaidapi-configuration-defaults for options
  101. },
  102. // optionally set additional config for plugin itself with MermaidPluginConfig
  103. mermaidPlugin: {
  104. class: "mermaid my-class", // set additional css classes for parent container
  105. },
  106. // vite config
  107. vite: {
  108. logLevel: 'info',
  109. server: {
  110. host: '0.0.0.0',
  111. port: 8361,
  112. allowedHosts: [
  113. 'raspberrypi', // 允许来自 raspberrypi 主机的访问
  114. 'raspberrypi.dev', // 允许来自 raspberrypi.dev 主机的访问
  115. 'raspberrypi.test', // 允许来自 raspberrypi.dev 主机的访问
  116. 'localhost' // 允许 localhost
  117. ],
  118. // allowedHosts: true, // 允许任何请求
  119. proxy: {
  120. [MalinePrefix]: {
  121. target: 'http://localhost:8360', // 后端Waline服务地址
  122. changeOrigin: true,
  123. rewrite: (path) => path.replace(new RegExp(`^${MalinePrefix}`), ''),
  124. // configure: (proxy, options) => {
  125. // proxy.on('proxyReq', (proxyReq, req) => {
  126. // console.log(`[proxyReq] ${req.method} ${req.url}`)
  127. // })
  128. // }
  129. }
  130. },
  131. watch: {
  132. ignored: ['**/node_modules/**', '**/.vitepress/**']
  133. }
  134. },
  135. plugins: [
  136. vueJsx(),
  137. // dev模式不再需要登录验证插件
  138. // {
  139. // name: "middleware",
  140. // configureServer(server) {
  141. // server.middlewares
  142. // .use(SseMid)
  143. // .use(AuthMid);
  144. // }
  145. // }
  146. ],
  147. ssr: {
  148. external: [],
  149. noExternal: ['naive-ui', 'date-fns', 'vueuc', 'vitepress', '@excalidraw/excalidraw'] // SSR 时强制编译
  150. },
  151. resolve: {
  152. alias: {
  153. // 'vitepress': resolve(__dirname, '../../packages/vitepress/src/client'),
  154. // 'dayjs/dayjs.min.js': 'dayjs/esm/index.js',
  155. // 'dayjs': 'dayjs/esm/index.js',
  156. '@': path.resolve(__dirname, './'),
  157. '@theme': path.resolve(__dirname, './theme'),
  158. '@docs': path.resolve(__dirname, '../'),
  159. },
  160. },
  161. optimizeDeps: {
  162. exclude: ['vitepress'], // 避免预构建
  163. },
  164. // Add this define to fix process.env error in Excalidraw
  165. // https://docs.excalidraw.com/docs/@excalidraw/excalidraw/faq#referenceerror-process-is-not-defined
  166. define: {
  167. 'process.env.IS_PREACT': JSON.stringify('true'),
  168. }
  169. },
  170. postRender(context) {
  171. const styleRegex = /<css-render-style>((.|\s)+)<\/css-render-style>/
  172. const vitepressPathRegex = /<vitepress-path>(.+)<\/vitepress-path>/
  173. const style = styleRegex.exec(context.content)?.[1]
  174. const vitepressPath = vitepressPathRegex.exec(context.content)?.[1]
  175. if (vitepressPath && style) {
  176. fileAndStyles[vitepressPath] = style
  177. }
  178. context.content = context.content.replace(styleRegex, '')
  179. context.content = context.content.replace(vitepressPathRegex, '')
  180. },
  181. transformHtml(code, id) {
  182. const html = id.split('/').pop()
  183. if (!html)
  184. return
  185. const style = fileAndStyles[`/${html}`]
  186. if (style) {
  187. return code.replace(/<\/head>/, `${style}</head>`)
  188. }
  189. }
  190. })
  191. )