docs/.vitepress/configs/index.ts

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

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