docs/.vitepress/configs/index.ts

6d09ee3bcdf292e5dc6d7e2b58b2610ce9cc4b0f
wotaku/docs/.vitepress/configs/index.ts history · blame · raw

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