From 155667234dd2f7baaf1a97e253964d60e9733ab1 Mon Sep 17 00:00:00 2001 From: pengzhanbo Date: Tue, 18 Jun 2024 14:35:24 +0800 Subject: [PATCH 01/14] refactor(theme): improve blog structure --- .../client/components/Blog/VPBlogArchives.vue | 3 +- .../client/components/Blog/VPBlogExtract.vue | 2 +- .../src/client/components/Blog/VPBlogNav.vue | 2 +- .../src/client/components/Blog/VPBlogTags.vue | 3 +- .../src/client/components/Blog/VPPostList.vue | 2 +- theme/src/client/composables/blog-archives.ts | 31 +++++ theme/src/client/composables/blog-extract.ts | 41 ++++++ .../{blog.ts => blog-post-list.ts} | 123 +----------------- theme/src/client/composables/blog-tags.ts | 62 +++++++++ theme/src/client/composables/index.ts | 6 +- 10 files changed, 148 insertions(+), 127 deletions(-) create mode 100644 theme/src/client/composables/blog-archives.ts create mode 100644 theme/src/client/composables/blog-extract.ts rename theme/src/client/composables/{blog.ts => blog-post-list.ts} (52%) create mode 100644 theme/src/client/composables/blog-tags.ts diff --git a/theme/src/client/components/Blog/VPBlogArchives.vue b/theme/src/client/components/Blog/VPBlogArchives.vue index 42890e6c..32a6bae4 100644 --- a/theme/src/client/components/Blog/VPBlogArchives.vue +++ b/theme/src/client/components/Blog/VPBlogArchives.vue @@ -1,6 +1,7 @@ + + + + diff --git a/theme/src/client/components/global/VPCardGrid.vue b/theme/src/client/components/global/VPCardGrid.vue new file mode 100644 index 00000000..5724bb24 --- /dev/null +++ b/theme/src/client/components/global/VPCardGrid.vue @@ -0,0 +1,23 @@ + + + diff --git a/theme/src/client/config.ts b/theme/src/client/config.ts index c21cafbe..d697285a 100644 --- a/theme/src/client/config.ts +++ b/theme/src/client/config.ts @@ -3,11 +3,13 @@ import './styles/index.css' import { defineClientConfig } from 'vuepress/client' import type { ClientConfig } from 'vuepress/client' import { h } from 'vue' -import VPBadge from './components/global/VPBadge.vue' +import VPHomeBox from '@theme/Home/VPHomeBox.vue' +import VPCard from '@theme/global/VPCard.vue' +import VPBadge from '@theme/global/VPBadge.vue' +import VPCardGrid from '@theme/global/VPCardGrid.vue' import { enhanceScrollBehavior, setupDarkMode, setupWatermark } from './composables/index.js' import Layout from './layouts/Layout.vue' import NotFound from './layouts/NotFound.vue' -import VPHomeBox from './components/Home/VPHomeBox.vue' export default defineClientConfig({ enhance({ app, router }) { @@ -18,6 +20,12 @@ export default defineClientConfig({ app.component('Badge', VPBadge) app.component('VPBadge', VPBadge) // alias + app.component('VPCard', VPCard) + app.component('Card', VPCard) + + app.component('VPCardGrid', VPCardGrid) + app.component('CardGrid', VPCardGrid) + app.component('DocSearch', () => { const SearchComponent = app.component('Docsearch') || app.component('SearchBox') diff --git a/theme/src/client/index.ts b/theme/src/client/index.ts index f4051017..2a17102e 100644 --- a/theme/src/client/index.ts +++ b/theme/src/client/index.ts @@ -11,6 +11,9 @@ export { default as Layout } from './layouts/Layout.vue' export { default as NotFound } from './layouts/NotFound.vue' export { default as VPBadge } from './components/global/VPBadge.vue' +export { default as VPCard } from './components/global/VPCard.vue' +export { default as VPCardGrid } from './components/global/VPCardGrid.vue' + export { default as VPImage } from './components/VPImage.vue' export { default as VPButton } from './components/VPButton.vue' export { default as VPLink } from './components/VPLink.vue' diff --git a/theme/src/node/config/extendsBundlerOptions.ts b/theme/src/node/config/extendsBundlerOptions.ts index a19d59dd..b753f17a 100644 --- a/theme/src/node/config/extendsBundlerOptions.ts +++ b/theme/src/node/config/extendsBundlerOptions.ts @@ -1,4 +1,4 @@ -import { addViteConfig, addViteOptimizeDepsInclude, addViteSsrNoExternal } from '@vuepress/helper' +import { addViteConfig, addViteOptimizeDepsExclude, addViteOptimizeDepsInclude, addViteSsrNoExternal } from '@vuepress/helper' import type { App } from 'vuepress' export function extendsBundlerOptions(bundlerOptions: any, app: App): void { @@ -9,6 +9,7 @@ export function extendsBundlerOptions(bundlerOptions: any, app: App): void { }) addViteOptimizeDepsInclude(bundlerOptions, app, '@vueuse/core', true) + addViteOptimizeDepsExclude(bundlerOptions, app, '@theme') addViteSsrNoExternal(bundlerOptions, app, [ '@vuepress/helper', diff --git a/theme/src/node/plugins/containerPlugins.ts b/theme/src/node/plugins/containerPlugins.ts index 502ce428..723f2dde 100644 --- a/theme/src/node/plugins/containerPlugins.ts +++ b/theme/src/node/plugins/containerPlugins.ts @@ -39,6 +39,15 @@ export const customContainerPlugins: Plugin[] = [ return '\n' }, }), + /** + * :::steps + * 1. 步骤 1 + * xxx + * 2. 步骤 2 + * xxx + * 3. ... + * ::: + */ containerPlugin({ type: 'steps', before() { @@ -48,6 +57,42 @@ export const customContainerPlugins: Plugin[] = [ return '' }, }), + /** + * ::: card title="xxx" icon="xxx" + * xxx + * ::: + */ + containerPlugin({ + type: 'card', + before(info) { + const title = resolveAttr(info, 'title') + const icon = resolveAttr(info, 'icon') + return `` + }, + after() { + return '' + }, + }), + + /** + * :::: card-grid + * ::: card + * xxx + * ::: + * ::: card + * xxx + * ::: + * :::: + */ + containerPlugin({ + type: 'card-grid', + before() { + return '' + }, + after() { + return '' + }, + }), ] /** From 126da9fb5f0e6342714bf4138b507bcacdfdedcc Mon Sep 17 00:00:00 2001 From: pengzhanbo Date: Wed, 19 Jun 2024 12:47:02 +0800 Subject: [PATCH 13/14] =?UTF-8?q?feat(theme):=20=E6=96=B0=E5=A2=9E=20=20``=20=E9=93=BE=E6=8E=A5=E5=8D=A1=E7=89=87=E7=BB=84?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/notes/theme/guide/功能/组件.md | 42 ++++++++ theme/src/client/components/global/VPCard.vue | 12 ++- .../client/components/global/VPLinkCard.vue | 97 +++++++++++++++++++ theme/src/client/config.ts | 51 +--------- theme/src/client/globalComponents.ts | 50 ++++++++++ 5 files changed, 199 insertions(+), 53 deletions(-) create mode 100644 theme/src/client/components/global/VPLinkCard.vue create mode 100644 theme/src/client/globalComponents.ts diff --git a/docs/notes/theme/guide/功能/组件.md b/docs/notes/theme/guide/功能/组件.md index 767fb11b..657e0b36 100644 --- a/docs/notes/theme/guide/功能/组件.md +++ b/docs/notes/theme/guide/功能/组件.md @@ -161,6 +161,38 @@ export default defineUserConfig({ 这里是卡片内容。 +## 链接卡片 + +使用 `` 组件在页面中显示链接卡片。 + +### Props + +| 名称 | 类型 | 默认值 | 说明 | +| ----------- | --------------------------- | ------ | ---------------------------------------------------------------- | +| title | `string` | `''` | 标题 | +| icon | `string \| { svg: string }` | `''` | 显示在标题左侧的图标,支持 iconify 所有图标,也可以使用 图片链接 | +| href | `string` | `''` | 链接 | +| description | `string` | `''` | 详情 | + +### 插槽 + +| 名称 | 说明 | +| ------- | ------------ | +| default | 卡片详情内容 | +| title | 自定义标题 | + +**输入:** + +```md + + +``` + +**输出:** + + + + ## 卡片排列容器 当你需要将多个卡片排列,可以使用 `` 组件。在空间足够时,多个卡片会自动排列。 @@ -176,6 +208,11 @@ export default defineUserConfig({ 这里是卡片内容。 + + + + + ``` **输出:** @@ -189,6 +226,11 @@ export default defineUserConfig({ + + + + + ## 首页布局容器 自定义首页时,使用 ``提供给 区域 的 包装容器。 diff --git a/theme/src/client/components/global/VPCard.vue b/theme/src/client/components/global/VPCard.vue index d1effcec..42776734 100644 --- a/theme/src/client/components/global/VPCard.vue +++ b/theme/src/client/components/global/VPCard.vue @@ -4,17 +4,15 @@ import { computed } from 'vue' const props = defineProps<{ title?: string - icon: string | { svg: string } + icon?: string | { svg: string } }>() -const icon = computed(() => { +const icon = computed(() => { if (props.icon?.[0] === '{') { try { return JSON.parse(icon) as { svg: string } } - catch { - return props.icon - } + catch {} } return props.icon }) @@ -51,6 +49,10 @@ const icon = computed(() => { box-shadow: var(--vp-shadow-2); } +.vp-card-wrapper :deep(.vp-iconify) { + margin: 0; +} + .vp-card-wrapper .title { display: flex; gap: 8px; diff --git a/theme/src/client/components/global/VPLinkCard.vue b/theme/src/client/components/global/VPLinkCard.vue new file mode 100644 index 00000000..bc7cdc51 --- /dev/null +++ b/theme/src/client/components/global/VPLinkCard.vue @@ -0,0 +1,97 @@ + + + + + diff --git a/theme/src/client/config.ts b/theme/src/client/config.ts index d697285a..80e927ea 100644 --- a/theme/src/client/config.ts +++ b/theme/src/client/config.ts @@ -2,12 +2,8 @@ import './styles/index.css' import { defineClientConfig } from 'vuepress/client' import type { ClientConfig } from 'vuepress/client' -import { h } from 'vue' -import VPHomeBox from '@theme/Home/VPHomeBox.vue' -import VPCard from '@theme/global/VPCard.vue' -import VPBadge from '@theme/global/VPBadge.vue' -import VPCardGrid from '@theme/global/VPCardGrid.vue' import { enhanceScrollBehavior, setupDarkMode, setupWatermark } from './composables/index.js' +import { globalComponents } from './globalComponents.js' import Layout from './layouts/Layout.vue' import NotFound from './layouts/NotFound.vue' @@ -15,51 +11,10 @@ export default defineClientConfig({ enhance({ app, router }) { setupDarkMode(app) enhanceScrollBehavior(router) - - // global component - app.component('Badge', VPBadge) - app.component('VPBadge', VPBadge) // alias - - app.component('VPCard', VPCard) - app.component('Card', VPCard) - - app.component('VPCardGrid', VPCardGrid) - app.component('CardGrid', VPCardGrid) - - app.component('DocSearch', () => { - const SearchComponent - = app.component('Docsearch') || app.component('SearchBox') - if (SearchComponent) - return h(SearchComponent) - - return null - }) - - app.component('PageComment', (props) => { - const CommentService = app.component('CommentService') - if (CommentService) - return h(CommentService, props) - - return null - }) - - app.component('Icon', (props) => { - const Iconify = app.component('Iconify') - if (Iconify) - return h(Iconify, props) - - return null - }) - - /** @deprecated */ - app.component('HomeBox', VPHomeBox) - app.component('VPHomeBox', VPHomeBox) + globalComponents(app) }, setup() { setupWatermark() }, - layouts: { - Layout, - NotFound, - }, + layouts: { Layout, NotFound }, }) as ClientConfig diff --git a/theme/src/client/globalComponents.ts b/theme/src/client/globalComponents.ts new file mode 100644 index 00000000..2c619d18 --- /dev/null +++ b/theme/src/client/globalComponents.ts @@ -0,0 +1,50 @@ +import type { App } from 'vue' +import { h } from 'vue' +import VPHomeBox from '@theme/Home/VPHomeBox.vue' +import VPCard from '@theme/global/VPCard.vue' +import VPLinkCard from '@theme/global/VPLinkCard.vue' +import VPBadge from '@theme/global/VPBadge.vue' +import VPCardGrid from '@theme/global/VPCardGrid.vue' + +export function globalComponents(app: App) { + app.component('Badge', VPBadge) + app.component('VPBadge', VPBadge) + + app.component('VPCard', VPCard) + app.component('Card', VPCard) + + app.component('VPCardGrid', VPCardGrid) + app.component('CardGrid', VPCardGrid) + + app.component('VPLinkCard', VPLinkCard) + app.component('LinkCard', VPLinkCard) + + app.component('DocSearch', () => { + const SearchComponent + = app.component('Docsearch') || app.component('SearchBox') + if (SearchComponent) + return h(SearchComponent) + + return null + }) + + app.component('PageComment', (props) => { + const CommentService = app.component('CommentService') + if (CommentService) + return h(CommentService, props) + + return null + }) + + app.component('Icon', (props) => { + const Iconify = app.component('Iconify') + if (Iconify) + return h(Iconify, props) + + return null + }) + + /** @deprecated */ + app.component('HomeBox', VPHomeBox) + app.component('VPHomeBox', VPHomeBox) +} From 85798e1c1c9fd21a20b8372f8ed523012f61006e Mon Sep 17 00:00:00 2001 From: pengzhanbo Date: Wed, 19 Jun 2024 12:57:20 +0800 Subject: [PATCH 14/14] chore: tweak --- theme/src/client/components/VPIcon.vue | 2 +- theme/src/client/components/global/VPLinkCard.vue | 13 +------------ 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/theme/src/client/components/VPIcon.vue b/theme/src/client/components/VPIcon.vue index 78958fe2..5a587d9a 100644 --- a/theme/src/client/components/VPIcon.vue +++ b/theme/src/client/components/VPIcon.vue @@ -37,7 +37,7 @@ const link = computed(() => { .vp__img { display: inline-block; height: 1em; - margin: 0.3em; + margin: 0 0.3em; vertical-align: middle; } diff --git a/theme/src/client/components/global/VPLinkCard.vue b/theme/src/client/components/global/VPLinkCard.vue index bc7cdc51..10900737 100644 --- a/theme/src/client/components/global/VPLinkCard.vue +++ b/theme/src/client/components/global/VPLinkCard.vue @@ -1,24 +1,13 @@