docs/.vitepress/configs/index.ts

2a9ff41b09725c1951e9a5a1095a2fded6bfb571
wotaku/docs/.vitepress/configs/index.ts history · blame · raw

151 lines · 4398 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'
 20
 21const GIT_COMMIT = process.env.NODE_ENV === 'development'
 22  ? 'dev'
 23  /** Github actions commit hash */
 24  : (process.env.GITHUB_SHA ??
 25    /** Commit hash from git */
 26    (await (await import('tinyexec'))
 27      .x('git', ['rev-parse', 'HEAD'])
 28      .then((result) => result.stdout.trim())) ??
 29    'dev')
 30
 31export const shared: UserConfig<DefaultTheme.Config> = {
 32  ...siteConfig,
 33  transformHead: async (context) => generateMeta(context, hostname),
 34  buildEnd: async (context) => {
 35    generateImages(context)
 36  },
 37  markdown: {
 38    emoji: { defs, shortcuts: aliases },
 39    config(md) {
 40      configureMarkdown(md)
 41    }
 42  },
 43  themeConfig: {
 44    search: {
 45      options: {
 46        miniSearch: {
 47          searchOptions: {
 48            combineWith: 'AND',
 49            fuzzy: false,
 50            // @ts-ignore
 51            boostDocument: (
 52              _,
 53              term,
 54              storedFields: Record<string, string | string[]>
 55            ) => {
 56              const titles = (storedFields?.titles as string[])
 57                .filter((t) => Boolean(t))
 58                .map((t) => t.toLowerCase())
 59              // Uprate if term appears in titles. Add bonus for higher levels (i.e. lower index)
 60              const titleIndex = titles
 61                .map((t, i) => (t?.includes(term) ? i : -1))
 62                .find((i) => i >= 0) ?? -1
 63              if (titleIndex >= 0) return 10000 - titleIndex
 64
 65              return 1
 66            }
 67          }
 68        },
 69        detailedView: true
 70      },
 71      provider: 'local'
 72    },
 73    logo: { src: '/asset/fav.png' },
 74    sidebar,
 75    // nav,
 76    socialLinks: [
 77      { icon: 'github', link: 'https://github.com/wotakumoe/Wotaku' },
 78      { icon: 'discord', link: 'https://discord.gg/vShRGx8ZBC' }
 79    ],
 80    footer: {
 81      message:
 82        `<a href="https://github.com/wotakumoe">The Wotaku Team</a> <span class="divider">|</span> <a href="https://github.com/wotakumoe/Wotaku/commit/${GIT_COMMIT}">${
 83          GIT_COMMIT.slice(
 84            0,
 85            7
 86          )
 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      Devtools(),
111      PageProperties(),
112      PagePropertiesMarkdownSection(),
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: /^.*\/VPNavBarSearch\.vue$/,
144          replacement: fileURLToPath(
145            new URL('../theme/components/NavBarSearch.vue', import.meta.url)
146          )
147        }
148      ]
149    }
150  }
151}