feat(theme): add page title badge (#183)

This commit is contained in:
pengzhanbo 2024-09-16 02:35:49 +08:00 committed by GitHub
parent db28c8bd8c
commit b99d926c0b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 26 additions and 2 deletions

View File

@ -3,6 +3,7 @@ title: 通用配置
author: pengzhanbo
createTime: 2024/03/02 20:01:09
permalink: /config/frontmatter/basic/
badge: 徽章 badge
---
## 概述
@ -14,7 +15,6 @@ permalink: /config/frontmatter/basic/
```md
---
title: 标题
author: 作者
createTime: 2024/03/02 20:01:09
permalink: /config/frontmatter/basic/
---
@ -56,6 +56,12 @@ permalink: /config/frontmatter/basic/
主题会在文件创建时,自动填充 当前文件名作为 文章标题。
### badge
- 类型: `string | { text: string, type?: 'info' | 'tip' | 'warning' | 'danger' }`
在文章标题右侧显示 徽章。
### createTime
- 类型: `string`

View File

@ -3,6 +3,7 @@ title: 轮播图
icon: dashicons:images-alt2
createTime: 2024/09/12 22:00:22
permalink: /guide/components/swiper/
badge: v1.0.0-rc.98 +
---
## 概述

View File

@ -1,4 +1,5 @@
<script lang="ts" setup>
import VPBadge from '@theme/global/VPBadge.vue'
import VPLink from '@theme/VPLink.vue'
import { useReadingTimeLocale } from '@vuepress/plugin-reading-time/client'
import { computed } from 'vue'
@ -28,12 +29,20 @@ const tags = computed(() => {
return []
})
const badge = computed(() => {
if (matter.value.badge) {
return typeof matter.value.badge === 'string' ? { text: matter.value.badge } : matter.value.badge
}
return false
})
const hasMeta = computed(() => readingTime.value.time || tags.value.length || createTime.value)
</script>
<template>
<h1 class="vp-doc-title page-title" :class="{ padding: !hasMeta }">
{{ page.title }}
<VPBadge v-if="badge" :type="badge.type || 'tip'" :text="badge.text" />
</h1>
<div v-if="hasMeta" class="vp-doc-meta">
<p v-if="readingTime.time && matter.readingTime !== false" class="reading-time">

View File

@ -25,7 +25,7 @@ export function extendsBundlerOptions(bundlerOptions: any, app: App): void {
])
if (isPackageExists('swiper')) {
addViteOptimizeDepsInclude(bundlerOptions, app, ['swiper/modules', 'swiper/vue'], true)
addViteOptimizeDepsInclude(bundlerOptions, app, ['swiper/modules', 'swiper/vue'])
addViteSsrNoExternal(bundlerOptions, app, ['swiper'])
}

View File

@ -17,4 +17,12 @@ export interface PlumeThemePostFrontmatter extends PlumeThemePageFrontmatter {
* @default false
*/
draft?: boolean
/**
*
*/
badge?: string | {
text: string
type?: 'info' | 'tip' | 'warning' | 'danger'
}
}