docs/.vitepress/configs/index.ts

3da2b7137fec2feaa6140e57f30ae8e04c455c96
wotaku/docs/.vitepress/configs/index.ts
Memenami Update top bar49ea0f0802 1 year ago

150 lines · 4493 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    footer: {
 76      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(
 77        0,
 78        7
 79      )}</a>`,
 80      copyright: 'made with love and eepy energy'
 81    }
 82  },
 83  vite: {
 84    optimizeDeps: {
 85      exclude: [
 86        '@nolebase/vitepress-plugin-enhanced-readabilities/client',
 87        '@nolebase/vitepress-plugin-git-changelog/client',
 88        '@nolebase/vitepress-plugin-page-properties/client'
 89      ]
 90    },
 91    ssr: {
 92      noExternal: [
 93        '@nolebase/vitepress-plugin-enhanced-readabilities',
 94        '@nolebase/vitepress-plugin-page-properties',
 95        '@nolebase/vitepress-plugin-git-changelog',
 96        '@nolebase/ui',
 97        '@fmhy/components'
 98      ]
 99    },
100    plugins: [
101      Devtools(),
102      PageProperties(),
103      PagePropertiesMarkdownSection(),
104      GitChangelog({
105        maxGitLogCount: 20,
106        repoURL: 'https://github.com/wotakumoe/Wotaku'
107      }),
108      GitChangelogMarkdownSection({ sections: { disableContributors: true } }),
109      UnoCSS({
110        configFile: '../unocss.config.ts'
111      }),
112      {
113        name: 'custom:adjust-order',
114        configResolved(c) {
115          movePlugin(
116            c.plugins as unknown as Plugin[],
117            'vitepress',
118            'before',
119            'unocss:transformers:pre'
120          )
121          movePlugin(
122            c.plugins as unknown as Plugin[],
123            'custom:tooltip-loader',
124            'before',
125            'vitepress'
126          )
127        }
128      }
129    ],
130    resolve: {
131      alias: [
132        {
133          find: /^.*\/VPBadge\.vue$/,
134          replacement: fileURLToPath(
135            new URL('../theme/components/Badge.vue', import.meta.url)
136          )
137        },
138        {
139          find: /^.*VPSwitchAppearance\.vue$/,
140          replacement: fileURLToPath(
141            new URL(
142              '../theme/components/VPSwitchAppearance.vue',
143              import.meta.url
144            )
145          )
146        }
147      ]
148    }
149  }
150}
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