docs/.vitepress/configs/index.ts

b4b14b6b7d8c938463d83adb5e8193bcff586cde
wotaku/docs/.vitepress/configs/index.ts
Duck Update index.ts897d4f94e1 5 months ago

153 lines · 4437 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    if (process.env.CI) {
 36      await generateImages(context)
 37    }
 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 = titles
 63                .map((t, i) => (t?.includes(term) ? i : -1))
 64                .find((i) => i >= 0) ?? -1
 65              if (titleIndex >= 0) return 10000 - titleIndex
 66
 67              return 1
 68            }
 69          }
 70        },
 71        detailedView: true
 72      },
 73      provider: 'local'
 74    },
 75    logo: { src: '/asset/fav.svg' },
 76    sidebar,
 77    // nav,
 78    socialLinks: [
 79      { icon: 'github', link: 'https://github.com/wotakumoe/Wotaku' },
 80      { icon: 'discord', link: 'https://discord.gg/vShRGx8ZBC' }
 81    ],
 82    footer: {
 83      message:
 84        `<a href="https://github.com/wotakumoe">The Wotaku Team</a> <span class="divider">|</span> <a href="https://github.com/wotakumoe/Wotaku/commit/${GIT_COMMIT}">${
 85          GIT_COMMIT.slice(
 86            0,
 87            7
 88          )
 89        }</a>`,
 90      copyright: 'made with love and eepy energy'
 91    }
 92  },
 93  vite: {
 94    experimental: {
 95      enableNativePlugin: true
 96    },
 97    optimizeDeps: {
 98      exclude: [
 99        '@nolebase/vitepress-plugin-enhanced-readabilities/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/ui',
108        '@fmhy/components'
109      ]
110    },
111    plugins: [
112      Devtools(),
113      PageProperties(),
114      PagePropertiesMarkdownSection(),
115      UnoCSS({
116        configFile: '../unocss.config.ts'
117      }),
118      {
119        name: 'custom:adjust-order',
120        configResolved(c) {
121          movePlugin(
122            c.plugins as unknown as Plugin[],
123            'vitepress',
124            'before',
125            'unocss:transformers:pre'
126          )
127          movePlugin(
128            c.plugins as unknown as Plugin[],
129            'custom:tooltip-loader',
130            'before',
131            'vitepress'
132          )
133        }
134      }
135    ],
136    resolve: {
137      alias: [
138        {
139          find: /^.*\/VPBadge\.vue$/,
140          replacement: fileURLToPath(
141            new URL('../theme/components/Badge.vue', import.meta.url)
142          )
143        },
144        {
145          find: /^.*\/VPNavBarSearch\.vue$/,
146          replacement: fileURLToPath(
147            new URL('../theme/components/NavBarSearch.vue', import.meta.url)
148          )
149        }
150      ]
151    }
152  }
153}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form