docs/.vitepress/configs/index.ts

c9e350253eadfc88a9f74d32c709bb81c8a7904a
wotaku/docs/.vitepress/configs/index.ts
Duck Revert "mememe"c9e350253e 5 months ago

176 lines · 5492 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    await 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          _render(src, env, md) {
 48            const html = md.render(src, env)
 49            if (env.frontmatter?.search === false) return html
 50            const BARE_TLDS = new Set([
 51              'org', 'com', 'net', 'io', 'co', 'gg', 'tv', 'me', 'app',
 52              'dev', 'xyz', 'info', 'moe', 'to', 'cc', 'fm', 'fr', 'jp'
 53            ])
 54            const seen = new Set<string>()
 55            for (const m of html.matchAll(/href="([^"]+)"/g)) {
 56              try {
 57                const u = new URL(m[1])
 58                const host = u.hostname.replace(/^www\./, '')
 59                if (!host) continue
 60                seen.add(host)
 61                const bare = host.split('.')[0]
 62                if (bare && !BARE_TLDS.has(bare)) seen.add(bare)
 63              } catch {
 64              }
 65            }
 66            for (const t of [...seen]) if (BARE_TLDS.has(t)) seen.delete(t)
 67            if (seen.size === 0) return html
 68            return `${html}\n<p class="vp-search-urls" aria-hidden="true" style="display:none">${
 69              [...seen].join(' ')
 70            }</p>`
 71          },
 72          searchOptions: {
 73            combineWith: 'AND',
 74            fuzzy: false,
 75            // @ts-ignore
 76            boostDocument: (
 77              _,
 78              term,
 79              storedFields: Record<string, string | string[]>
 80            ) => {
 81              const titles = (storedFields?.titles as string[])
 82                .filter((t) => Boolean(t))
 83                .map((t) => t.toLowerCase())
 84              // Uprate if term appears in titles. Add bonus for higher levels (i.e. lower index)
 85              const titleIndex = titles
 86                .map((t, i) => (t?.includes(term) ? i : -1))
 87                .find((i) => i >= 0) ?? -1
 88              if (titleIndex >= 0) return 10000 - titleIndex
 89
 90              return 1
 91            }
 92          }
 93        },
 94        detailedView: true
 95      },
 96      provider: 'local'
 97    },
 98    logo: { src: '/asset/fav.svg' },
 99    sidebar,
100    // nav,
101    socialLinks: [
102      { icon: 'github', link: 'https://github.com/wotakumoe/Wotaku' },
103      { icon: 'discord', link: 'https://discord.gg/vShRGx8ZBC' }
104    ],
105    footer: {
106      message:
107        `<a href="https://github.com/wotakumoe">The Wotaku Team</a> <span class="divider">|</span> <a href="https://github.com/wotakumoe/Wotaku/commit/${GIT_COMMIT}">${
108          GIT_COMMIT.slice(
109            0,
110            7
111          )
112        }</a>`,
113      copyright: 'made with love and eepy energy'
114    }
115  },
116  vite: {
117    experimental: {
118      enableNativePlugin: true
119    },
120    optimizeDeps: {
121      exclude: [
122        '@nolebase/vitepress-plugin-enhanced-readabilities/client',
123        '@nolebase/vitepress-plugin-page-properties/client'
124      ]
125    },
126    ssr: {
127      noExternal: [
128        '@nolebase/vitepress-plugin-enhanced-readabilities',
129        '@nolebase/vitepress-plugin-page-properties',
130        '@nolebase/ui',
131        '@fmhy/components'
132      ]
133    },
134    plugins: [
135      Devtools(),
136      PageProperties(),
137      PagePropertiesMarkdownSection(),
138      UnoCSS({
139        configFile: '../unocss.config.ts'
140      }),
141      {
142        name: 'custom:adjust-order',
143        configResolved(c) {
144          movePlugin(
145            c.plugins as unknown as Plugin[],
146            'vitepress',
147            'before',
148            'unocss:transformers:pre'
149          )
150          movePlugin(
151            c.plugins as unknown as Plugin[],
152            'custom:tooltip-loader',
153            'before',
154            'vitepress'
155          )
156        }
157      }
158    ],
159    resolve: {
160      alias: [
161        {
162          find: /^.*\/VPBadge\.vue$/,
163          replacement: fileURLToPath(
164            new URL('../theme/components/Badge.vue', import.meta.url)
165          )
166        },
167        {
168          find: /^.*\/VPNavBarSearch\.vue$/,
169          replacement: fileURLToPath(
170            new URL('../theme/components/NavBarSearch.vue', import.meta.url)
171          )
172        }
173      ]
174    }
175  }
176}
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