/** * All Rights Reserved * * Copyright (c) 2025 taskylizard * * 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. */ import { PageProperties, PagePropertiesMarkdownSection } from '@nolebase/vitepress-plugin-page-properties/vite' import { fileURLToPath, URL } from 'node:url' import UnoCSS from 'unocss/vite' import Devtools from 'vite-plugin-vue-devtools' import type { DefaultTheme, Plugin, UserConfig } from 'vitepress' import { hostname, sidebar, siteConfig } from './constants' import { generateImages, generateMeta } from './hooks' import { configureMarkdown } from './markdown' import { aliases, defs, movePlugin } from './markdown/emoji' const GIT_COMMIT = process.env.NODE_ENV === 'development' ? 'dev' /** Github actions commit hash */ : (process.env.GITHUB_SHA ?? /** Commit hash from git */ (await (await import('tinyexec')) .x('git', ['rev-parse', 'HEAD']) .then((result) => result.stdout.trim())) ?? 'dev') export const shared: UserConfig = { ...siteConfig, transformHead: async (context) => generateMeta(context, hostname), buildEnd: async (context) => { await generateImages(context) }, markdown: { emoji: { defs, shortcuts: aliases }, config(md) { configureMarkdown(md) } }, themeConfig: { search: { options: { miniSearch: { _render(src, env, md) { const html = md.render(src, env) if (env.frontmatter?.search === false) return html const BARE_TLDS = new Set([ 'org', 'com', 'net', 'io', 'co', 'gg', 'tv', 'me', 'app', 'dev', 'xyz', 'info', 'moe', 'to', 'cc', 'fm', 'fr', 'jp' ]) const seen = new Set() for (const m of html.matchAll(/href="([^"]+)"/g)) { try { const u = new URL(m[1]) const host = u.hostname.replace(/^www\./, '') if (!host) continue seen.add(host) const bare = host.split('.')[0] if (bare && !BARE_TLDS.has(bare)) seen.add(bare) } catch { } } for (const t of [...seen]) if (BARE_TLDS.has(t)) seen.delete(t) if (seen.size === 0) return html return `${html}\n` }, searchOptions: { combineWith: 'AND', fuzzy: false, // @ts-ignore boostDocument: ( _, term, storedFields: Record ) => { const titles = (storedFields?.titles as string[]) .filter((t) => Boolean(t)) .map((t) => t.toLowerCase()) // Uprate if term appears in titles. Add bonus for higher levels (i.e. lower index) const titleIndex = titles .map((t, i) => (t?.includes(term) ? i : -1)) .find((i) => i >= 0) ?? -1 if (titleIndex >= 0) return 10000 - titleIndex return 1 } } }, detailedView: true }, provider: 'local' }, logo: { src: '/asset/fav.svg' }, sidebar, // nav, socialLinks: [ { icon: 'github', link: 'https://github.com/wotakumoe/Wotaku' }, { icon: 'discord', link: 'https://discord.gg/vShRGx8ZBC' } ], footer: { message: `The Wotaku Team | ${ GIT_COMMIT.slice( 0, 7 ) }`, copyright: 'made with love and eepy energy' } }, vite: { experimental: { enableNativePlugin: true }, optimizeDeps: { exclude: [ '@nolebase/vitepress-plugin-enhanced-readabilities/client', '@nolebase/vitepress-plugin-page-properties/client' ] }, ssr: { noExternal: [ '@nolebase/vitepress-plugin-enhanced-readabilities', '@nolebase/vitepress-plugin-page-properties', '@nolebase/ui', '@fmhy/components' ] }, plugins: [ Devtools(), PageProperties(), PagePropertiesMarkdownSection(), UnoCSS({ configFile: '../unocss.config.ts' }), { name: 'custom:adjust-order', configResolved(c) { movePlugin( c.plugins as unknown as Plugin[], 'vitepress', 'before', 'unocss:transformers:pre' ) movePlugin( c.plugins as unknown as Plugin[], 'custom:tooltip-loader', 'before', 'vitepress' ) } } ], resolve: { alias: [ { find: /^.*\/VPBadge\.vue$/, replacement: fileURLToPath( new URL('../theme/components/Badge.vue', import.meta.url) ) }, { find: /^.*\/VPNavBarSearch\.vue$/, replacement: fileURLToPath( new URL('../theme/components/NavBarSearch.vue', import.meta.url) ) } ] } } }