From b502ff62d03bad8ac7bd02cbc88511beef2e6b59 Mon Sep 17 00:00:00 2001 From: WRXinYue <3322543587@qq.com> Date: Wed, 21 Aug 2024 14:35:04 +0800 Subject: [PATCH] refactor: optimal config --- pnpm-lock.yaml | 289 +---------------------------------------- theme/node/config.ts | 75 +++++++++++ theme/node/index.ts | 105 +-------------- theme/node/plugins.ts | 22 ++++ theme/package.json | 10 +- theme/types/index.d.ts | 28 ++-- theme/valaxy.config.ts | 9 +- 7 files changed, 129 insertions(+), 409 deletions(-) create mode 100644 theme/node/config.ts create mode 100644 theme/node/plugins.ts diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4cc90465..5e6367a6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -183,7 +183,10 @@ importers: version: 0.0.5 valaxy-addon-waline: specifier: ^0.1.5 - version: 0.1.5(typescript@5.5.4)(valaxy@0.19.9(@babel/parser@7.25.3)(@types/markdown-it@14.1.2)(@types/node@22.4.1)(axios@1.7.4)(postcss@8.4.41)(rollup@4.21.0)(typescript@5.5.4)) + version: 0.1.5(typescript@5.5.4)(valaxy@0.19.9(@babel/parser@7.25.3)(@types/markdown-it@14.1.2)(@types/node@22.4.1)(axios@1.7.4)(postcss@8.4.41)(rollup@2.79.1)(terser@5.31.6)(typescript@5.5.4)) + vite-plugin-pwa: + specifier: ^0.20.1 + version: 0.20.1(vite@5.4.1(@types/node@22.4.1)(sass@1.77.8)(terser@5.31.6))(workbox-build@7.1.1)(workbox-window@7.1.0) devDependencies: '@types/d3': specifier: ^7.4.3 @@ -194,9 +197,6 @@ importers: valaxy: specifier: ^0.19.9 version: 0.19.9(@babel/parser@7.25.3)(@types/markdown-it@14.1.2)(@types/node@22.4.1)(axios@1.7.4)(postcss@8.4.41)(rollup@2.79.1)(terser@5.31.6)(typescript@5.5.4) - vite-plugin-pwa: - specifier: ^0.20.1 - version: 0.20.1(vite@5.4.1(@types/node@22.4.1)(sass@1.77.8)(terser@5.31.6))(workbox-build@7.1.1)(workbox-window@7.1.0) packages: @@ -8571,17 +8571,6 @@ snapshots: - rollup - supports-color - '@unocss/astro@0.62.2(rollup@4.21.0)(vite@5.4.1(@types/node@22.4.1)(sass@1.77.8))': - dependencies: - '@unocss/core': 0.62.2 - '@unocss/reset': 0.62.2 - '@unocss/vite': 0.62.2(rollup@4.21.0)(vite@5.4.1(@types/node@22.4.1)(sass@1.77.8)) - optionalDependencies: - vite: 5.4.1(@types/node@22.4.1)(sass@1.77.8)(terser@5.31.6) - transitivePeerDependencies: - - rollup - - supports-color - '@unocss/cli@0.62.2(rollup@2.79.1)': dependencies: '@ampproject/remapping': 2.3.0 @@ -8788,23 +8777,6 @@ snapshots: - rollup - supports-color - '@unocss/vite@0.62.2(rollup@4.21.0)(vite@5.4.1(@types/node@22.4.1)(sass@1.77.8))': - dependencies: - '@ampproject/remapping': 2.3.0 - '@rollup/pluginutils': 5.1.0(rollup@4.21.0) - '@unocss/config': 0.62.2 - '@unocss/core': 0.62.2 - '@unocss/inspector': 0.62.2 - '@unocss/scope': 0.62.2 - '@unocss/transformer-directives': 0.62.2 - chokidar: 3.6.0 - magic-string: 0.30.11 - tinyglobby: 0.2.2 - vite: 5.4.1(@types/node@22.4.1)(sass@1.77.8)(terser@5.31.6) - transitivePeerDependencies: - - rollup - - supports-color - '@valaxyjs/devtools@0.19.9(debug@4.3.6)(rollup@2.79.1)': dependencies: '@rollup/pluginutils': 5.1.0(rollup@2.79.1) @@ -8840,11 +8812,6 @@ snapshots: vite: 5.4.1(@types/node@22.4.1)(sass@1.77.8)(terser@5.31.6) vue: 3.4.38(typescript@5.5.4) - '@vitejs/plugin-vue@5.1.2(vite@5.4.1(@types/node@22.4.1)(sass@1.77.8))(vue@3.4.38(typescript@5.5.4))': - dependencies: - vite: 5.4.1(@types/node@22.4.1)(sass@1.77.8)(terser@5.31.6) - vue: 3.4.38(typescript@5.5.4) - '@vitest/expect@1.6.0': dependencies: '@vitest/spy': 1.6.0 @@ -8994,18 +8961,6 @@ snapshots: transitivePeerDependencies: - vite - '@vue/devtools-core@7.3.8(vite@5.4.1(@types/node@22.4.1)(sass@1.77.8))(vue@3.4.38(typescript@5.5.4))': - dependencies: - '@vue/devtools-kit': 7.3.8 - '@vue/devtools-shared': 7.3.8 - mitt: 3.0.1 - nanoid: 3.3.7 - pathe: 1.1.2 - vite-hot-client: 0.2.3(vite@5.4.1(@types/node@22.4.1)(sass@1.77.8)) - vue: 3.4.38(typescript@5.5.4) - transitivePeerDependencies: - - vite - '@vue/devtools-kit@7.3.8': dependencies: '@vue/devtools-shared': 7.3.8 @@ -12808,35 +12763,6 @@ snapshots: - rollup - supports-color - unocss@0.62.2(postcss@8.4.41)(rollup@4.21.0)(vite@5.4.1(@types/node@22.4.1)(sass@1.77.8)): - dependencies: - '@unocss/astro': 0.62.2(rollup@4.21.0)(vite@5.4.1(@types/node@22.4.1)(sass@1.77.8)) - '@unocss/cli': 0.62.2(rollup@4.21.0) - '@unocss/core': 0.62.2 - '@unocss/extractor-arbitrary-variants': 0.62.2 - '@unocss/postcss': 0.62.2(postcss@8.4.41) - '@unocss/preset-attributify': 0.62.2 - '@unocss/preset-icons': 0.62.2 - '@unocss/preset-mini': 0.62.2 - '@unocss/preset-tagify': 0.62.2 - '@unocss/preset-typography': 0.62.2 - '@unocss/preset-uno': 0.62.2 - '@unocss/preset-web-fonts': 0.62.2 - '@unocss/preset-wind': 0.62.2 - '@unocss/reset': 0.62.2 - '@unocss/transformer-attributify-jsx': 0.62.2 - '@unocss/transformer-attributify-jsx-babel': 0.62.2 - '@unocss/transformer-compile-class': 0.62.2 - '@unocss/transformer-directives': 0.62.2 - '@unocss/transformer-variant-group': 0.62.2 - '@unocss/vite': 0.62.2(rollup@4.21.0)(vite@5.4.1(@types/node@22.4.1)(sass@1.77.8)) - optionalDependencies: - vite: 5.4.1(@types/node@22.4.1)(sass@1.77.8)(terser@5.31.6) - transitivePeerDependencies: - - postcss - - rollup - - supports-color - unpipe@1.0.0: {} unplugin-ast@0.10.0(rollup@2.79.1): @@ -12927,19 +12853,6 @@ snapshots: transitivePeerDependencies: - rollup - unplugin-vue-markdown@0.26.2(rollup@4.21.0)(vite@5.4.1(@types/node@22.4.1)(sass@1.77.8)): - dependencies: - '@mdit-vue/plugin-component': 2.1.3 - '@mdit-vue/plugin-frontmatter': 2.1.3 - '@mdit-vue/types': 2.1.0 - '@rollup/pluginutils': 5.1.0(rollup@4.21.0) - '@types/markdown-it': 14.1.2 - markdown-it: 14.1.0 - unplugin: 1.12.2 - vite: 5.4.1(@types/node@22.4.1)(sass@1.77.8)(terser@5.31.6) - transitivePeerDependencies: - - rollup - unplugin-vue-router@0.10.7(rollup@2.79.1)(vue-router@4.4.3(vue@3.4.38(typescript@5.5.4)))(vue@3.4.38(typescript@5.5.4)): dependencies: '@babel/types': 7.25.2 @@ -13048,10 +12961,10 @@ snapshots: valaxy-addon-vercount@0.0.5: {} - valaxy-addon-waline@0.1.5(typescript@5.5.4)(valaxy@0.19.9(@babel/parser@7.25.3)(@types/markdown-it@14.1.2)(@types/node@22.4.1)(axios@1.7.4)(postcss@8.4.41)(rollup@4.21.0)(typescript@5.5.4)): + valaxy-addon-waline@0.1.5(typescript@5.5.4)(valaxy@0.19.9(@babel/parser@7.25.3)(@types/markdown-it@14.1.2)(@types/node@22.4.1)(axios@1.7.4)(postcss@8.4.41)(rollup@2.79.1)(terser@5.31.6)(typescript@5.5.4)): dependencies: '@waline/client': 3.3.0(typescript@5.5.4) - valaxy: 0.19.9(@babel/parser@7.25.3)(@types/markdown-it@14.1.2)(@types/node@22.4.1)(axios@1.7.4)(postcss@8.4.41)(rollup@4.21.0)(typescript@5.5.4) + valaxy: 0.19.9(@babel/parser@7.25.3)(@types/markdown-it@14.1.2)(@types/node@22.4.1)(axios@1.7.4)(postcss@8.4.41)(rollup@2.79.1)(terser@5.31.6)(typescript@5.5.4) transitivePeerDependencies: - '@vue/composition-api' - typescript @@ -13270,113 +13183,6 @@ snapshots: - utf-8-validate - vue-i18n-bridge - valaxy@0.19.9(@babel/parser@7.25.3)(@types/markdown-it@14.1.2)(@types/node@22.4.1)(axios@1.7.4)(postcss@8.4.41)(rollup@4.21.0)(typescript@5.5.4): - dependencies: - '@antfu/utils': 0.7.10 - '@ctrl/tinycolor': 4.1.0 - '@iconify-json/ri': 1.1.22 - '@intlify/unplugin-vue-i18n': 4.0.0(rollup@4.21.0)(vue-i18n@9.14.0(vue@3.4.38(typescript@5.5.4))) - '@types/katex': 0.16.7 - '@types/luxon': 3.4.2 - '@unhead/addons': 1.9.16(rollup@4.21.0) - '@unhead/schema-org': 1.9.16 - '@unhead/vue': 1.9.16(vue@3.4.38(typescript@5.5.4)) - '@valaxyjs/devtools': 0.19.9(debug@4.3.6)(rollup@4.21.0) - '@valaxyjs/utils': 0.19.9 - '@vitejs/plugin-vue': 5.1.2(vite@5.4.1(@types/node@22.4.1)(sass@1.77.8))(vue@3.4.38(typescript@5.5.4)) - '@vue/devtools-api': 7.3.8 - '@vueuse/core': 11.0.0(vue@3.4.38(typescript@5.5.4)) - '@vueuse/integrations': 11.0.0(axios@1.7.4)(fuse.js@7.0.0)(nprogress@0.2.0)(qrcode@1.5.4)(vue@3.4.38(typescript@5.5.4)) - consola: 3.2.3 - critters: 0.0.24 - cross-spawn: 7.0.3 - css-i18n: 0.0.2 - date-fns: 3.6.0 - date-fns-tz: 3.1.3(date-fns@3.6.0) - debug: 4.3.6(supports-color@5.5.0) - defu: 6.1.4 - ejs: 3.1.10 - escape-html: 1.0.3 - feed: 4.2.2 - fs-extra: 11.2.0 - fuse.js: 7.0.0 - gray-matter: 4.0.3 - hookable: 5.5.3 - html-to-text: 9.0.5 - is-installed-globally: 1.0.0 - jiti: 1.21.6 - js-base64: 3.7.7 - js-yaml: 4.1.0 - katex: 0.16.11 - lru-cache: 11.0.0 - luxon: 3.5.0 - markdown-it: 14.1.0 - markdown-it-anchor: 9.0.1(@types/markdown-it@14.1.2)(markdown-it@14.1.0) - markdown-it-attrs: 4.2.0(markdown-it@14.1.0) - markdown-it-container: 4.0.0 - markdown-it-emoji: 3.0.0 - markdown-it-footnote: 4.0.0 - markdown-it-image-figures: 2.1.1(markdown-it@14.1.0) - markdown-it-table-of-contents: 0.6.0 - markdown-it-task-lists: 2.1.1 - medium-zoom: 1.1.0 - mermaid: 10.9.1 - nprogress: 0.2.0 - open: 10.1.0 - ora: 8.0.1 - pascalcase: 2.0.0 - pathe: 1.1.2 - pinia: 2.2.2(typescript@5.5.4)(vue@3.4.38(typescript@5.5.4)) - qrcode: 1.5.4 - sass: 1.77.8 - shiki: 1.14.1 - star-markdown-css: 0.5.1 - unocss: 0.62.2(postcss@8.4.41)(rollup@4.21.0)(vite@5.4.1(@types/node@22.4.1)(sass@1.77.8)) - unplugin-vue-components: 0.27.4(@babel/parser@7.25.3)(rollup@4.21.0)(vue@3.4.38(typescript@5.5.4)) - unplugin-vue-markdown: 0.26.2(rollup@4.21.0)(vite@5.4.1(@types/node@22.4.1)(sass@1.77.8)) - unplugin-vue-router: 0.10.7(rollup@4.21.0)(vue-router@4.4.3(vue@3.4.38(typescript@5.5.4)))(vue@3.4.38(typescript@5.5.4)) - vanilla-lazyload: 19.1.3 - vite: 5.4.1(@types/node@22.4.1)(sass@1.77.8)(terser@5.31.6) - vite-plugin-vue-devtools: 7.3.8(rollup@4.21.0)(vite@5.4.1(@types/node@22.4.1)(sass@1.77.8))(vue@3.4.38(typescript@5.5.4)) - vite-plugin-vue-layouts: 0.11.0(vite@5.4.1(@types/node@22.4.1)(sass@1.77.8))(vue-router@4.4.3(vue@3.4.38(typescript@5.5.4)))(vue@3.4.38(typescript@5.5.4)) - vite-ssg: 0.23.7(critters@0.0.24)(vite@5.4.1(@types/node@22.4.1)(sass@1.77.8))(vue-router@4.4.3(vue@3.4.38(typescript@5.5.4)))(vue@3.4.38(typescript@5.5.4)) - vite-ssg-sitemap: 0.6.1 - vue: 3.4.38(typescript@5.5.4) - vue-i18n: 9.14.0(vue@3.4.38(typescript@5.5.4)) - vue-router: 4.4.3(vue@3.4.38(typescript@5.5.4)) - yargs: 17.7.2 - transitivePeerDependencies: - - '@babel/parser' - - '@nuxt/kit' - - '@types/markdown-it' - - '@types/node' - - '@unocss/webpack' - - '@vue/composition-api' - - async-validator - - axios - - bufferutil - - canvas - - change-case - - drauu - - focus-trap - - idb-keyval - - jwt-decode - - less - - lightningcss - - petite-vue-i18n - - postcss - - rollup - - sass-embedded - - sortablejs - - stylus - - sugarss - - supports-color - - terser - - typescript - - universal-cookie - - utf-8-validate - - vue-i18n-bridge - validate-npm-package-license@3.0.4: dependencies: spdx-correct: 3.2.0 @@ -13388,10 +13194,6 @@ snapshots: dependencies: vite: 5.4.1(@types/node@22.4.1)(sass@1.77.8)(terser@5.31.6) - vite-hot-client@0.2.3(vite@5.4.1(@types/node@22.4.1)(sass@1.77.8)): - dependencies: - vite: 5.4.1(@types/node@22.4.1)(sass@1.77.8)(terser@5.31.6) - vite-node@1.6.0(@types/node@22.4.1)(sass@1.77.8)(terser@5.31.6): dependencies: cac: 6.7.14 @@ -13442,22 +13244,6 @@ snapshots: - rollup - supports-color - vite-plugin-inspect@0.8.5(rollup@4.21.0)(vite@5.4.1(@types/node@22.4.1)(sass@1.77.8)): - dependencies: - '@antfu/utils': 0.7.10 - '@rollup/pluginutils': 5.1.0(rollup@4.21.0) - debug: 4.3.6(supports-color@5.5.0) - error-stack-parser-es: 0.1.5 - fs-extra: 11.2.0 - open: 10.1.0 - perfect-debounce: 1.0.0 - picocolors: 1.0.1 - sirv: 2.0.4 - vite: 5.4.1(@types/node@22.4.1)(sass@1.77.8)(terser@5.31.6) - transitivePeerDependencies: - - rollup - - supports-color - vite-plugin-pwa@0.20.1(vite@5.4.1(@types/node@22.4.1)(sass@1.77.8)(terser@5.31.6))(workbox-build@7.1.1)(workbox-window@7.1.0): dependencies: debug: 4.3.6(supports-color@5.5.0) @@ -13501,22 +13287,6 @@ snapshots: - supports-color - vue - vite-plugin-vue-devtools@7.3.8(rollup@4.21.0)(vite@5.4.1(@types/node@22.4.1)(sass@1.77.8))(vue@3.4.38(typescript@5.5.4)): - dependencies: - '@vue/devtools-core': 7.3.8(vite@5.4.1(@types/node@22.4.1)(sass@1.77.8))(vue@3.4.38(typescript@5.5.4)) - '@vue/devtools-kit': 7.3.8 - '@vue/devtools-shared': 7.3.8 - execa: 8.0.1 - sirv: 2.0.4 - vite: 5.4.1(@types/node@22.4.1)(sass@1.77.8)(terser@5.31.6) - vite-plugin-inspect: 0.8.5(rollup@4.21.0)(vite@5.4.1(@types/node@22.4.1)(sass@1.77.8)) - vite-plugin-vue-inspector: 5.1.3(vite@5.4.1(@types/node@22.4.1)(sass@1.77.8)) - transitivePeerDependencies: - - '@nuxt/kit' - - rollup - - supports-color - - vue - vite-plugin-vue-inspector@5.1.3(vite@5.4.1(@types/node@22.4.1)(sass@1.77.8)(terser@5.31.6)): dependencies: '@babel/core': 7.25.2 @@ -13532,21 +13302,6 @@ snapshots: transitivePeerDependencies: - supports-color - vite-plugin-vue-inspector@5.1.3(vite@5.4.1(@types/node@22.4.1)(sass@1.77.8)): - dependencies: - '@babel/core': 7.25.2 - '@babel/plugin-proposal-decorators': 7.24.7(@babel/core@7.25.2) - '@babel/plugin-syntax-import-attributes': 7.24.7(@babel/core@7.25.2) - '@babel/plugin-syntax-import-meta': 7.10.4(@babel/core@7.25.2) - '@babel/plugin-transform-typescript': 7.25.2(@babel/core@7.25.2) - '@vue/babel-plugin-jsx': 1.2.2(@babel/core@7.25.2) - '@vue/compiler-dom': 3.4.38 - kolorist: 1.8.0 - magic-string: 0.30.11 - vite: 5.4.1(@types/node@22.4.1)(sass@1.77.8)(terser@5.31.6) - transitivePeerDependencies: - - supports-color - vite-plugin-vue-layouts@0.11.0(vite@5.4.1(@types/node@22.4.1)(sass@1.77.8)(terser@5.31.6))(vue-router@4.4.3(vue@3.4.38(typescript@5.5.4)))(vue@3.4.38(typescript@5.5.4)): dependencies: debug: 4.3.6(supports-color@5.5.0) @@ -13557,16 +13312,6 @@ snapshots: transitivePeerDependencies: - supports-color - vite-plugin-vue-layouts@0.11.0(vite@5.4.1(@types/node@22.4.1)(sass@1.77.8))(vue-router@4.4.3(vue@3.4.38(typescript@5.5.4)))(vue@3.4.38(typescript@5.5.4)): - dependencies: - debug: 4.3.6(supports-color@5.5.0) - fast-glob: 3.3.2 - vite: 5.4.1(@types/node@22.4.1)(sass@1.77.8)(terser@5.31.6) - vue: 3.4.38(typescript@5.5.4) - vue-router: 4.4.3(vue@3.4.38(typescript@5.5.4)) - transitivePeerDependencies: - - supports-color - vite-ssg-sitemap@0.6.1: {} vite-ssg@0.23.7(critters@0.0.24)(vite@5.4.1(@types/node@22.4.1)(sass@1.77.8)(terser@5.31.6))(vue-router@4.4.3(vue@3.4.38(typescript@5.5.4)))(vue@3.4.38(typescript@5.5.4)): @@ -13591,28 +13336,6 @@ snapshots: - supports-color - utf-8-validate - vite-ssg@0.23.7(critters@0.0.24)(vite@5.4.1(@types/node@22.4.1)(sass@1.77.8))(vue-router@4.4.3(vue@3.4.38(typescript@5.5.4)))(vue@3.4.38(typescript@5.5.4)): - dependencies: - '@unhead/dom': 1.9.16 - '@unhead/vue': 1.9.16(vue@3.4.38(typescript@5.5.4)) - fs-extra: 11.2.0 - html-minifier: 4.0.0 - html5parser: 2.0.2 - jsdom: 24.1.1 - kolorist: 1.8.0 - prettier: 3.3.3 - vite: 5.4.1(@types/node@22.4.1)(sass@1.77.8)(terser@5.31.6) - vue: 3.4.38(typescript@5.5.4) - yargs: 17.7.2 - optionalDependencies: - critters: 0.0.24 - vue-router: 4.4.3(vue@3.4.38(typescript@5.5.4)) - transitivePeerDependencies: - - bufferutil - - canvas - - supports-color - - utf-8-validate - vite@5.4.1(@types/node@22.4.1)(sass@1.77.8)(terser@5.31.6): dependencies: esbuild: 0.21.5 diff --git a/theme/node/config.ts b/theme/node/config.ts new file mode 100644 index 00000000..7b36afd5 --- /dev/null +++ b/theme/node/config.ts @@ -0,0 +1,75 @@ +import type { ThemeConfig } from '../types' + +export const defaultThemeConfig: ThemeConfig = { + valaxyDarkOptions: { + circleTransition: true, + }, + + colors: { + primary: '#0078E7', + }, + + navbarTitle: '', + + favicon: false, + + banner: { + title: 'Hello, sakura', + motto: 'You got to put the past behind you before you can move on.', + urls: [], + style: '', + + typewriter: false, + enableHitokoto: false, + }, + + navbar: [], + + sidebar: [], + sidebarOptions: { + position: 'left', + offset: true, + initialState: false, + persistence: 'session', + enableOnDesktop: false, + showCounts: false, + }, + + footer: { + since: 2024, + icon: { + animated: true, + url: 'https://sponsors.yunyoujun.cn', + title: 'WRXinYue', + }, + + powered: true, + }, + + scrollDamping: false, +} + +/** + * generateSafelist by config + * @param themeConfig + */ +export function generateSafelist(themeConfig: ThemeConfig) { + const safelist: string[] = [] + + const footerIcon = themeConfig.footer?.icon?.img + + if (footerIcon) + safelist.push(footerIcon) + + themeConfig.navbar?.forEach((navItem) => { + if (navItem.icon) + safelist.push(navItem.icon) + }) + + themeConfig.sidebar?.forEach((sidebarItem) => { + if (typeof sidebarItem !== 'string' && sidebarItem.icon) + safelist.push(sidebarItem.icon) + }) + + return safelist +} diff --git a/theme/node/index.ts b/theme/node/index.ts index f165323b..f9ea6e7f 100644 --- a/theme/node/index.ts +++ b/theme/node/index.ts @@ -1,103 +1,2 @@ -import type { PluginOption } from 'vite' -import type { ResolvedValaxyOptions } from 'valaxy' -import type { ThemeConfig, ThemeUserConfig } from '../types' - -/** - * Default Config - */ -export const defaultThemeConfig: ThemeUserConfig = { - valaxyDarkOptions: { - circleTransition: true, - }, - - colors: { - primary: '#0078E7', - }, - - navbarTitle: '', - - favicon: false, - - banner: { - title: 'Hello, sakura', - motto: 'You got to put the past behind you before you can move on.', - urls: [], - style: '', - - typewriter: false, - enableHitokoto: false, - }, - - navbar: [], - - sidebar: [], - sidebarOptions: { - position: 'left', - offset: true, - initialState: false, - persistence: 'session', - enableOnDesktop: false, - showCounts: false, - }, - - footer: { - since: 2024, - icon: { - animated: true, - url: 'https://sponsors.yunyoujun.cn', - title: 'WRXinYue', - }, - - powered: true, - }, -} - -// write a vite plugin -// https://vitejs.dev/guide/api-plugin.html -export function themePlugin(options: ResolvedValaxyOptions): PluginOption { - const themeConfig = options.config.themeConfig || {} - - return { - name: 'valaxy-theme-sakura', - - config() { - return { - css: { - preprocessorOptions: { - scss: { - additionalData: `$c-primary: ${themeConfig.colors?.primary || '#0078E7' - } !default;`, - }, - }, - }, - - valaxy: {}, - } - }, - } -} - -/** - * generateSafelist by config - * @param themeConfig - */ -export function generateSafelist(themeConfig: ThemeConfig) { - const safelist: string[] = [] - - const footerIcon = themeConfig.footer?.icon?.img - - if (footerIcon) - safelist.push(footerIcon) - - themeConfig.navbar?.forEach((navItem) => { - if (navItem.icon) - safelist.push(navItem.icon) - }) - - themeConfig.sidebar?.forEach((sidebarItem) => { - if (typeof sidebarItem !== 'string' && sidebarItem.icon) - safelist.push(sidebarItem.icon) - }) - - return safelist -} +export * from './config' +export * from './plugins' diff --git a/theme/node/plugins.ts b/theme/node/plugins.ts new file mode 100644 index 00000000..2a0f87be --- /dev/null +++ b/theme/node/plugins.ts @@ -0,0 +1,22 @@ +import type { PluginOption } from 'vite' +import type { ThemeConfig } from '../types' + +export function themePlugin(themeConfig: ThemeConfig): PluginOption { + return { + name: 'valaxy-theme-sakura', + + config() { + return { + css: { + preprocessorOptions: { + scss: { + additionalData: `$c-primary: ${themeConfig.colors?.primary} !default;`, + }, + }, + }, + + valaxy: {}, + } + }, + } +} diff --git a/theme/package.json b/theme/package.json index a5171a5e..3bc84339 100644 --- a/theme/package.json +++ b/theme/package.json @@ -1,6 +1,6 @@ { "name": "valaxy-theme-sakura", - "version": "0.6.7-alpha.1", + "version": "0.6.7-alpha.4", "packageManager": "pnpm@9.5.0", "author": { "email": "3322543587@qq.com", @@ -25,7 +25,6 @@ "types": "types/index.d.ts", "peerDependencies": { "d3-force": "^3.0.0", - "typeit": "^8.8.3", "valaxy-addon-hitokoto": "^0.0.1", "valaxy-addon-vercount": "^0.0.5", "valaxy-addon-waline": "^0.1.5" @@ -33,12 +32,13 @@ "dependencies": { "@iconify-json/fa6-solid": "^1.1.20", "@iconify-json/mdi": "^1.1.64", - "@studio-freight/lenis": "^1.0.37" + "@studio-freight/lenis": "^1.0.37", + "typeit": "^8.8.3", + "vite-plugin-pwa": "^0.20.1" }, "devDependencies": { "@types/d3": "^7.4.3", "@types/d3-force": "^3.0.9", - "valaxy": "^0.19.9", - "vite-plugin-pwa": "^0.20.1" + "valaxy": "^0.19.9" } } diff --git a/theme/types/index.d.ts b/theme/types/index.d.ts index ecb33045..9b829027 100644 --- a/theme/types/index.d.ts +++ b/theme/types/index.d.ts @@ -26,7 +26,7 @@ export interface ThemeConfig extends DefaultTheme.Config { banner: Partial - articlePinned: { + articlePinned?: { title?: string desc?: string img?: string @@ -45,26 +45,26 @@ export interface ThemeConfig extends DefaultTheme.Config { favicon: boolean navbar: NavItem[] navbarTitle: string | string[] - navbarOptions: { - title?: string | string[] - invert?: boolean - col?: boolean - autoHide?: boolean - animIn?: string - animOut?: string - } + navbarOptions?: Partial<{ + title: string | string[] + invert: boolean + col: boolean + autoHide: boolean + animIn: string + animOut: string + }> /** * Article */ - article: { + article?: { navigationMerge?: boolean } - outlineTitle: string + outlineTitle?: string // Pagination configuration - pagination: { + pagination?: { /** * Animations are valid only for the 'infinite-scroll' type */ @@ -96,9 +96,9 @@ export interface ThemeConfig extends DefaultTheme.Config { scrollDamping: boolean - notFoundImage: string + notFoundImage?: string - notice: { + notice?: { message: string } } diff --git a/theme/valaxy.config.ts b/theme/valaxy.config.ts index a0d208fb..19d62d3b 100644 --- a/theme/valaxy.config.ts +++ b/theme/valaxy.config.ts @@ -3,18 +3,19 @@ import { addonVercount } from 'valaxy-addon-vercount' import { addonHitokoto } from 'valaxy-addon-hitokoto' import { VitePWA } from 'vite-plugin-pwa' import type { PluginOption } from 'vite' +import defu from 'defu' import { defaultThemeConfig, generateSafelist, themePlugin } from './node' import type { ThemeConfig } from './types' export default defineTheme((options) => { - const themeConfig = options.config.themeConfig || {} - const siteConfig = options.config.siteConfig || {} + const { siteConfig, themeConfig: userThemeConfig } = options.config + const themeConfig = defu(userThemeConfig || {}, defaultThemeConfig) return { - themeConfig: defaultThemeConfig as ThemeConfig, + themeConfig: defaultThemeConfig, vite: { plugins: [ - themePlugin(options), + themePlugin(themeConfig), VitePWA({ registerType: 'autoUpdate', injectRegister: 'auto',