From 97dfa4a2dd24ca6c040bc18ef49092d2cc9d6a17 Mon Sep 17 00:00:00 2001 From: Rizumu Ayaka Date: Sun, 5 May 2024 23:31:53 +0800 Subject: [PATCH] feat(page-properties): added new custom dynamic page properties Signed-off-by: Rizumu Ayaka --- .../src/plugins/nolebase/index.ts | 18 +++++ .../src/client/components/PageProperties.vue | 19 +++++- .../components/PagePropertiesEditor.vue | 19 +++++- .../src/client/composables/propertyType.ts | 14 +++- .../src/client/types.ts | 30 ++++++--- .../src/client/virtual.d.ts | 67 ------------------- 6 files changed, 86 insertions(+), 81 deletions(-) diff --git a/packages/unconfig-vitepress/src/plugins/nolebase/index.ts b/packages/unconfig-vitepress/src/plugins/nolebase/index.ts index 9709da6b..0e0184f1 100644 --- a/packages/unconfig-vitepress/src/plugins/nolebase/index.ts +++ b/packages/unconfig-vitepress/src/plugins/nolebase/index.ts @@ -141,6 +141,15 @@ const defaultOptions: NolebasePluginPresetOptions = { dateFnsLocaleName: 'enUS', }, }, + { + key: 'someCustomProperty', + type: 'dynamic', + title: 'Some custom property', + options: { + type: 'custom', + getter: () => 'Custom value', + }, + }, ], 'zh-CN': [ { @@ -184,6 +193,15 @@ const defaultOptions: NolebasePluginPresetOptions = { dateFnsLocaleName: 'zhCN', }, }, + { + key: 'someCustomProperty', + type: 'dynamic', + title: '自定义属性', + options: { + type: 'custom', + getter: () => 'Custom value', + }, + }, ], }, }, diff --git a/packages/vitepress-plugin-page-properties/src/client/components/PageProperties.vue b/packages/vitepress-plugin-page-properties/src/client/components/PageProperties.vue index 6c7e1203..82c0baee 100644 --- a/packages/vitepress-plugin-page-properties/src/client/components/PageProperties.vue +++ b/packages/vitepress-plugin-page-properties/src/client/components/PageProperties.vue @@ -4,8 +4,10 @@ import { useData } from 'vitepress' import { NuTag } from '@nolebase/ui' import { InjectionKey } from '../constants' +import type { Property } from '../types' import { isDatetimeProperty, + isDynamicCustomProperty, isDynamicReadingTimeProperty, isDynamicWordsCountProperty, isLinkProperty, @@ -22,7 +24,8 @@ import ProgressBar from './ProgressBar.vue' import Datetime from './Datetime.vue' const options = inject(InjectionKey, {}) -const { lang, frontmatter } = useData() +const vitePressData = useData() +const { lang, frontmatter } = vitePressData const { t } = useI18n() const rawPath = useRawPath() const pagePropertiesData = usePageProperties() @@ -148,6 +151,9 @@ const readingTime = computed(() => { + @@ -245,6 +251,17 @@ const readingTime = computed(() => { {{ formatDurationFromValue(readingTime, property.pageProperty.options.dateFnsLocaleName || lang) }} + +