docs/.vitepress/configs/index.ts
157 lines · 4775 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, 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 // biome-ignore lint/suspicious/useAwait: <explanation>
37 buildEnd: async (context) => {
38 generateImages(context)
39 },
40 markdown: {
41 emoji: { defs, shortcuts: aliases },
42 config(md) {
43 configureMarkdown(md)
44 }
45 },
46 themeConfig: {
47 search: {
48 options: {
49 miniSearch: {
50 searchOptions: {
51 combineWith: 'AND',
52 fuzzy: false,
53 // @ts-ignore
54 boostDocument: (
55 _,
56 term,
57 storedFields: Record<string, string | string[]>
58 ) => {
59 const titles = (storedFields?.titles as string[])
60 .filter((t) => Boolean(t))
61 .map((t) => t.toLowerCase())
62 // Uprate if term appears in titles. Add bonus for higher levels (i.e. lower index)
63 const titleIndex =
64 titles
65 .map((t, i) => (t?.includes(term) ? i : -1))
66 .find((i) => i >= 0) ?? -1
67 if (titleIndex >= 0) return 10000 - titleIndex
68
69 return 1
70 }
71 }
72 },
73 detailedView: true
74 },
75 provider: 'local'
76 },
77 logo: { src: '/asset/fav.png' },
78 sidebar,
79 nav,
80 socialLinks: [
81 { icon: 'github', link: 'https://github.com/wotakumoe/Wotaku' },
82 { icon: 'discord', link: 'https://discord.gg/vShRGx8ZBC' },
83 {
84 icon: 'bluesky',
85 link: 'https://bsky.app/profile/wotaku.wiki'
86 }
87 ],
88 footer: {
89 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(
90 0,
91 7
92 )}</a>`,
93 copyright: 'made with love and eepy energy'
94 }
95 },
96 vite: {
97 optimizeDeps: {
98 exclude: [
99 '@nolebase/vitepress-plugin-enhanced-readabilities/client',
100 '@nolebase/vitepress-plugin-git-changelog/client',
101 '@nolebase/vitepress-plugin-page-properties/client'
102 ]
103 },
104 ssr: {
105 noExternal: [
106 '@nolebase/vitepress-plugin-enhanced-readabilities',
107 '@nolebase/vitepress-plugin-page-properties',
108 '@nolebase/vitepress-plugin-git-changelog',
109 '@nolebase/ui',
110 '@fmhy/components'
111 ]
112 },
113 plugins: [
114 Devtools(),
115 PageProperties(),
116 PagePropertiesMarkdownSection(),
117 GitChangelog({
118 maxGitLogCount: 20,
119 repoURL: 'https://github.com/wotakumoe/Wotaku'
120 }),
121 GitChangelogMarkdownSection({ sections: { disableContributors: true } }),
122 UnoCSS({
123 configFile: '../unocss.config.ts'
124 }),
125 {
126 name: 'custom:adjust-order',
127 configResolved(c) {
128 movePlugin(
129 c.plugins as any,
130 'vitepress',
131 'before',
132 'unocss:transformers:pre'
133 )
134 }
135 }
136 ],
137 resolve: {
138 alias: [
139 {
140 find: /^.*\/VPBadge\.vue$/,
141 replacement: fileURLToPath(
142 new URL('../theme/components/Badge.vue', import.meta.url)
143 )
144 },
145 {
146 find: /^.*VPSwitchAppearance\.vue$/,
147 replacement: fileURLToPath(
148 new URL(
149 '../theme/components/VPSwitchAppearance.vue',
150 import.meta.url
151 )
152 )
153 }
154 ]
155 }
156 }
157}