docs/.vitepress/configs/index.ts
176 lines · 5143 bytes
1/**
2 * All Rights Reserved
3 *
4 * Copyright (c) 2025 taskylizard
5 *
6 * All rights reserved. This code and its associated files may not be copied, modified, distributed, sublicensed, or used in any form, in whole or in part, without prior written permission from the copyright holder.
7 */
8import {
9 PageProperties,
10 PagePropertiesMarkdownSection
11} from '@nolebase/vitepress-plugin-page-properties/vite'
12import { fileURLToPath, URL } from 'node:url'
13import UnoCSS from 'unocss/vite'
14import { createLogger } from 'vite'
15import Devtools from 'vite-plugin-vue-devtools'
16import type { DefaultTheme, Plugin, UserConfig } from 'vitepress'
17import { hostname, sidebar, siteConfig } from './constants'
18import { generateImages, generateMeta } from './hooks'
19import { configureMarkdown } from './markdown'
20import { aliases, defs, movePlugin } from './markdown/emoji'
21import { collectPageLinks, urlSearchDevPlugin, writeUrlSearchIndex } from '../plugins/urlSearchPlugin'
22
23const logger = createLogger()
24const warn = logger.warn
25const warnOnce = logger.warnOnce
26
27function shouldSuppressWarning(message: string) {
28 return message.includes('[lightningcss minify] Unknown at rule: @property') ||
29 message.includes('Some chunks are larger than')
30}
31
32logger.warn = (message, options) => {
33 if (shouldSuppressWarning(message)) return
34 warn(message, options)
35}
36
37logger.warnOnce = (message, options) => {
38 if (shouldSuppressWarning(message)) return
39 warnOnce(message, options)
40}
41
42const GIT_COMMIT = process.env.NODE_ENV === 'development'
43 ? 'dev'
44 : (process.env.GITHUB_SHA ??
45 (await (await import('tinyexec'))
46 .x('git', ['rev-parse', 'HEAD'])
47 .then((result) => result.stdout.trim())) ??
48 'dev')
49
50export const shared: UserConfig<DefaultTheme.Config> = {
51 ...siteConfig,
52 transformHead: async (context) => generateMeta(context, hostname),
53 buildEnd: async (context) => {
54 writeUrlSearchIndex(context.outDir)
55 if (process.env.CI) {
56 await generateImages(context)
57 }
58 },
59 markdown: {
60 emoji: { defs, shortcuts: aliases },
61 config(md) {
62 configureMarkdown(md)
63 }
64 },
65 themeConfig: {
66 search: {
67 options: {
68 miniSearch: {
69 searchOptions: {
70 combineWith: 'AND',
71 fuzzy: false,
72 // @ts-ignore
73 boostDocument: (
74 _,
75 term,
76 storedFields: Record<string, string | string[]>
77 ) => {
78 const titles = (storedFields?.titles as string[])
79 .filter((t) => Boolean(t))
80 .map((t) => t.toLowerCase())
81 const titleIndex = titles
82 .map((t, i) => (t?.includes(term) ? i : -1))
83 .find((i) => i >= 0) ?? -1
84 if (titleIndex >= 0) return 10000 - titleIndex
85 return 1
86 }
87 }
88 },
89 _render(src, env, md) {
90 collectPageLinks(src, env.relativePath)
91 return md.render(src, env)
92 },
93 detailedView: true
94 },
95 provider: 'local'
96 },
97 logo: { src: '/asset/fav.svg' },
98 sidebar,
99 socialLinks: [
100 { icon: 'github', link: 'https://github.com/wotakumoe/Wotaku' },
101 { icon: 'discord', link: 'https://discord.gg/vShRGx8ZBC' }
102 ],
103 footer: {
104 message:
105 `<a href="https://github.com/wotakumoe">The Wotaku Team</a> <span class="divider">|</span> <a href="https://github.com/wotakumoe/Wotaku/commit/${GIT_COMMIT}">${
106 GIT_COMMIT.slice(0, 7)
107 }</a>`,
108 copyright: 'made with love and eepy energy'
109 }
110 },
111 vite: {
112 customLogger: logger,
113 experimental: {
114 enableNativePlugin: true
115 },
116 build: {
117 cssMinify: 'lightningcss'
118 },
119 optimizeDeps: {
120 exclude: [
121 '@nolebase/vitepress-plugin-enhanced-readabilities/client',
122 '@nolebase/vitepress-plugin-page-properties/client'
123 ]
124 },
125 ssr: {
126 noExternal: [
127 '@nolebase/vitepress-plugin-enhanced-readabilities',
128 '@nolebase/vitepress-plugin-page-properties',
129 '@nolebase/ui',
130 '@fmhy/components'
131 ]
132 },
133 plugins: [
134 urlSearchDevPlugin(),
135 Devtools(),
136 PageProperties(),
137 PagePropertiesMarkdownSection(),
138 UnoCSS({
139 configFile: '../unocss.config.ts'
140 }),
141 {
142 name: 'custom:adjust-order',
143 configResolved(c) {
144 movePlugin(
145 c.plugins as unknown as Plugin[],
146 'vitepress',
147 'before',
148 'unocss:transformers:pre'
149 )
150 movePlugin(
151 c.plugins as unknown as Plugin[],
152 'custom:tooltip-loader',
153 'before',
154 'vitepress'
155 )
156 }
157 }
158 ],
159 resolve: {
160 alias: [
161 {
162 find: /^.*\/VPBadge\.vue$/,
163 replacement: fileURLToPath(
164 new URL('../theme/components/Badge.vue', import.meta.url)
165 )
166 },
167 {
168 find: /^.*\/VPNavBarSearch\.vue$/,
169 replacement: fileURLToPath(
170 new URL('../theme/components/NavBarSearch.vue', import.meta.url)
171 )
172 }
173 ]
174 }
175 }
176}