docs/.vitepress/configs/index.ts

3df0ffeb7d8713f61ba2fa9a8554133c597af3e1
wotaku/docs/.vitepress/configs/index.ts history · blame · raw

162 lines · 4813 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  GitChangelog,
 10  GitChangelogMarkdownSection
 11} from '@nolebase/vitepress-plugin-git-changelog/vite'
 12import {
 13  PageProperties,
 14  PagePropertiesMarkdownSection
 15} from '@nolebase/vitepress-plugin-page-properties/vite'
 16import { fileURLToPath, URL } from 'node:url'
 17import UnoCSS from 'unocss/vite'
 18import Devtools from 'vite-plugin-vue-devtools'
 19import type { DefaultTheme, Plugin, UserConfig } from 'vitepress'
 20import { hostname, sidebar, siteConfig } from './constants'
 21import { generateImages, generateMeta } from './hooks'
 22import { configureMarkdown } from './markdown'
 23import { aliases, defs, movePlugin } from './markdown/emoji'
 24
 25const GIT_COMMIT = process.env.NODE_ENV === 'development'
 26  ? 'dev'
 27  /** Github actions commit hash */
 28  : (process.env.GITHUB_SHA ??
 29    /** Commit hash from git */
 30    (await (await import('tinyexec'))
 31      .x('git', ['rev-parse', 'HEAD'])
 32      .then((result) => result.stdout.trim())) ??
 33    'dev')
 34
 35export const shared: UserConfig<DefaultTheme.Config> = {
 36  ...siteConfig,
 37  transformHead: async (context) => generateMeta(context, hostname),
 38  buildEnd: async (context) => {
 39    generateImages(context)
 40  },
 41  markdown: {
 42    emoji: { defs, shortcuts: aliases },
 43    config(md) {
 44      configureMarkdown(md)
 45    }
 46  },
 47  themeConfig: {
 48    search: {
 49      options: {
 50        miniSearch: {
 51          searchOptions: {
 52            combineWith: 'AND',
 53            fuzzy: false,
 54            // @ts-ignore
 55            boostDocument: (
 56              _,
 57              term,
 58              storedFields: Record<string, string | string[]>
 59            ) => {
 60              const titles = (storedFields?.titles as string[])
 61                .filter((t) => Boolean(t))
 62                .map((t) => t.toLowerCase())
 63              // Uprate if term appears in titles. Add bonus for higher levels (i.e. lower index)
 64              const titleIndex = 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    footer: {
 85      message:
 86        `<a href="https://github.com/wotakumoe">The Wotaku Team</a> <span class="divider">|</span> <a href="https://github.com/wotakumoe/Wotaku/commit/${GIT_COMMIT}">${
 87          GIT_COMMIT.slice(
 88            0,
 89            7
 90          )
 91        }</a>`,
 92      copyright: 'made with love and eepy energy'
 93    }
 94  },
 95  vite: {
 96    experimental: {
 97      enableNativePlugin: true
 98    },
 99    optimizeDeps: {
100      exclude: [
101        '@nolebase/vitepress-plugin-enhanced-readabilities/client',
102        '@nolebase/vitepress-plugin-git-changelog/client',
103        '@nolebase/vitepress-plugin-page-properties/client'
104      ]
105    },
106    ssr: {
107      noExternal: [
108        '@nolebase/vitepress-plugin-enhanced-readabilities',
109        '@nolebase/vitepress-plugin-page-properties',
110        '@nolebase/vitepress-plugin-git-changelog',
111        '@nolebase/ui',
112        '@fmhy/components'
113      ]
114    },
115    plugins: [
116      Devtools(),
117      PageProperties(),
118      PagePropertiesMarkdownSection(),
119      GitChangelog({
120        maxGitLogCount: 20,
121        repoURL: 'https://github.com/wotakumoe/Wotaku'
122      }),
123      GitChangelogMarkdownSection({ sections: { disableContributors: true } }),
124      UnoCSS({
125        configFile: '../unocss.config.ts'
126      }),
127      {
128        name: 'custom:adjust-order',
129        configResolved(c) {
130          movePlugin(
131            c.plugins as unknown as Plugin[],
132            'vitepress',
133            'before',
134            'unocss:transformers:pre'
135          )
136          movePlugin(
137            c.plugins as unknown as Plugin[],
138            'custom:tooltip-loader',
139            'before',
140            'vitepress'
141          )
142        }
143      }
144    ],
145    resolve: {
146      alias: [
147        {
148          find: /^.*\/VPBadge\.vue$/,
149          replacement: fileURLToPath(
150            new URL('../theme/components/Badge.vue', import.meta.url)
151          )
152        },
153        {
154          find: /^.*\/VPNavBarSearch\.vue$/,
155          replacement: fileURLToPath(
156            new URL('../theme/components/NavBarSearch.vue', import.meta.url)
157          )
158        }
159      ]
160    }
161  }
162}