docs/.vitepress/configs/index.ts
162 lines · 4904 bytes
1/**
2 * Copyright (c) 2024 taskylizard
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import type { DefaultTheme, Plugin, UserConfig } from 'vitepress'
17import { generateImages, generateMeta } from './hooks'
18import { defs, movePlugin, aliases } from './markdown/emoji'
19import {
20 PageProperties,
21 PagePropertiesMarkdownSection
22} from '@nolebase/vitepress-plugin-page-properties/vite'
23import {
24 GitChangelog,
25 GitChangelogMarkdownSection
26} from '@nolebase/vitepress-plugin-git-changelog/vite'
27import { fileURLToPath, URL } from 'node:url'
28import UnoCSS from 'unocss/vite'
29import Devtools from 'vite-plugin-vue-devtools'
30import { configureMarkdown } from './markdown'
31import { GIT_COMMIT, hostname, nav, sidebar, siteConfig } from './constants'
32
33export const shared: UserConfig<DefaultTheme.Config> = {
34 ...siteConfig,
35 transformHead: async (context) => generateMeta(context, hostname),
36 buildEnd: async (context) => {
37 generateImages(context)
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 // Uprate if term appears in titles. Add bonus for higher levels (i.e. lower index)
62 const titleIndex =
63 titles
64 .map((t, i) => (t?.includes(term) ? i : -1))
65 .find((i) => i >= 0) ?? -1
66 if (titleIndex >= 0) return 10000 - titleIndex
67
68 return 1
69 }
70 }
71 },
72 detailedView: true
73 },
74 provider: 'local'
75 },
76 logo: { src: '/asset/fav.png' },
77 sidebar,
78 nav,
79 socialLinks: [
80 { icon: 'github', link: 'https://github.com/wotakumoe/Wotaku' },
81 { icon: 'discord', link: 'https://discord.gg/vShRGx8ZBC' },
82 {
83 icon: 'bluesky',
84 link: 'https://bsky.app/profile/wotaku.wiki'
85 }
86 ],
87 footer: {
88 message: `<a href="https://github.com/wotakumoe">The Wotaku Team</a> <span class="divider">|</span> <a href="https://github.com/wotakumoe/Wotaku/commit/${GIT_COMMIT}">${GIT_COMMIT.slice(
89 0,
90 7
91 )}</a>`,
92 copyright: 'made with love and eepy energy'
93 }
94 },
95 vite: {
96 optimizeDeps: {
97 exclude: [
98 '@nolebase/vitepress-plugin-enhanced-readabilities/client',
99 '@nolebase/vitepress-plugin-git-changelog/client',
100 '@nolebase/vitepress-plugin-page-properties/client'
101 ]
102 },
103 ssr: {
104 noExternal: [
105 '@nolebase/vitepress-plugin-enhanced-readabilities',
106 '@nolebase/vitepress-plugin-page-properties',
107 '@nolebase/vitepress-plugin-git-changelog',
108 '@nolebase/ui',
109 '@fmhy/components'
110 ]
111 },
112 plugins: [
113 Devtools(),
114 PageProperties(),
115 PagePropertiesMarkdownSection(),
116 GitChangelog({
117 maxGitLogCount: 20,
118 repoURL: 'https://github.com/wotakumoe/Wotaku'
119 }),
120 GitChangelogMarkdownSection({ sections: { disableContributors: true } }),
121 UnoCSS({
122 configFile: '../unocss.config.ts'
123 }),
124 {
125 name: 'custom:adjust-order',
126 configResolved(c) {
127 movePlugin(
128 c.plugins as unknown as Plugin[],
129 'vitepress',
130 'before',
131 'unocss:transformers:pre'
132 )
133 movePlugin(
134 c.plugins as unknown as Plugin[],
135 'custom:tooltip-loader',
136 'before',
137 'vitepress'
138 )
139 }
140 }
141 ],
142 resolve: {
143 alias: [
144 {
145 find: /^.*\/VPBadge\.vue$/,
146 replacement: fileURLToPath(
147 new URL('../theme/components/Badge.vue', import.meta.url)
148 )
149 },
150 {
151 find: /^.*VPSwitchAppearance\.vue$/,
152 replacement: fileURLToPath(
153 new URL(
154 '../theme/components/VPSwitchAppearance.vue',
155 import.meta.url
156 )
157 )
158 }
159 ]
160 }
161 }
162}