docs/.vitepress/configs/index.ts
152 lines · 4523 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 Devtools from 'vite-plugin-vue-devtools'
15import type { DefaultTheme, Plugin, UserConfig } from 'vitepress'
16import { hostname, sidebar, siteConfig } from './constants'
17import { generateImages, generateMeta } from './hooks'
18import { configureMarkdown } from './markdown'
19import { aliases, defs, movePlugin } from './markdown/emoji'
20import { collectPageLinks, urlSearchDevPlugin, writeUrlSearchIndex } from '../plugins/urlSearchPlugin'
21
22const GIT_COMMIT = process.env.NODE_ENV === 'development'
23 ? 'dev'
24 : (process.env.GITHUB_SHA ??
25 (await (await import('tinyexec'))
26 .x('git', ['rev-parse', 'HEAD'])
27 .then((result) => result.stdout.trim())) ??
28 'dev')
29
30export const shared: UserConfig<DefaultTheme.Config> = {
31 ...siteConfig,
32 transformHead: async (context) => generateMeta(context, hostname),
33 buildEnd: async (context) => {
34 writeUrlSearchIndex(context.outDir)
35 if (process.env.CI) {
36 await generateImages(context)
37 }
38 },
39 markdown: {
40 emoji: { defs, shortcuts: aliases },
41 config(md) {
42 configureMarkdown(md)
43 }
44 },
45 themeConfig: {
46 search: {
47 options: {
48 miniSearch: {
49 searchOptions: {
50 combineWith: 'AND',
51 fuzzy: false,
52 // @ts-ignore
53 boostDocument: (
54 _,
55 term,
56 storedFields: Record<string, string | string[]>
57 ) => {
58 const titles = (storedFields?.titles as string[])
59 .filter((t) => Boolean(t))
60 .map((t) => t.toLowerCase())
61 const titleIndex = titles
62 .map((t, i) => (t?.includes(term) ? i : -1))
63 .find((i) => i >= 0) ?? -1
64 if (titleIndex >= 0) return 10000 - titleIndex
65 return 1
66 }
67 }
68 },
69 _render(src, env, md) {
70 collectPageLinks(src, env.relativePath)
71 return md.render(src, env)
72 },
73 detailedView: true
74 },
75 provider: 'local'
76 },
77 logo: { src: '/asset/fav.svg' },
78 sidebar,
79 socialLinks: [
80 { icon: 'github', link: 'https://github.com/wotakumoe/Wotaku' },
81 { icon: 'discord', link: 'https://discord.gg/vShRGx8ZBC' }
82 ],
83 footer: {
84 message:
85 `<a href="https://github.com/wotakumoe">The Wotaku Team</a> <span class="divider">|</span> <a href="https://github.com/wotakumoe/Wotaku/commit/${GIT_COMMIT}">${
86 GIT_COMMIT.slice(0, 7)
87 }</a>`,
88 copyright: 'made with love and eepy energy'
89 }
90 },
91 vite: {
92 experimental: {
93 enableNativePlugin: true
94 },
95 optimizeDeps: {
96 exclude: [
97 '@nolebase/vitepress-plugin-enhanced-readabilities/client',
98 '@nolebase/vitepress-plugin-page-properties/client'
99 ]
100 },
101 ssr: {
102 noExternal: [
103 '@nolebase/vitepress-plugin-enhanced-readabilities',
104 '@nolebase/vitepress-plugin-page-properties',
105 '@nolebase/ui',
106 '@fmhy/components'
107 ]
108 },
109 plugins: [
110 urlSearchDevPlugin(),
111 Devtools(),
112 PageProperties(),
113 PagePropertiesMarkdownSection(),
114 UnoCSS({
115 configFile: '../unocss.config.ts'
116 }),
117 {
118 name: 'custom:adjust-order',
119 configResolved(c) {
120 movePlugin(
121 c.plugins as unknown as Plugin[],
122 'vitepress',
123 'before',
124 'unocss:transformers:pre'
125 )
126 movePlugin(
127 c.plugins as unknown as Plugin[],
128 'custom:tooltip-loader',
129 'before',
130 'vitepress'
131 )
132 }
133 }
134 ],
135 resolve: {
136 alias: [
137 {
138 find: /^.*\/VPBadge\.vue$/,
139 replacement: fileURLToPath(
140 new URL('../theme/components/Badge.vue', import.meta.url)
141 )
142 },
143 {
144 find: /^.*\/VPNavBarSearch\.vue$/,
145 replacement: fileURLToPath(
146 new URL('../theme/components/NavBarSearch.vue', import.meta.url)
147 )
148 }
149 ]
150 }
151 }
152}