From bc9eb6c65eb47c58fb2ad8600f47e5cb653ce6cc Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Fri, 26 Apr 2024 03:11:09 +0800 Subject: [PATCH 1/2] fix(theme-yun): incorrect ago value when ``fm.updated`` is not exist --- packages/valaxy-theme-yun/components/YunMdTimeWarning.vue | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/valaxy-theme-yun/components/YunMdTimeWarning.vue b/packages/valaxy-theme-yun/components/YunMdTimeWarning.vue index 88e3195ee..4e6d6a653 100644 --- a/packages/valaxy-theme-yun/components/YunMdTimeWarning.vue +++ b/packages/valaxy-theme-yun/components/YunMdTimeWarning.vue @@ -13,12 +13,16 @@ dayjs.extend(relativeTime) const { t } = useI18n() +const updated = computed(() => { + return dayjs(fm.value.updated || fm.value.date) +}) + /** * when the post is updated more than 180 days ago, show a warning * default 180 days, you can set `time_warning` in frontmatter to change it */ const time_warning = computed(() => { - const diff = dayjs().valueOf() - dayjs(fm.value.updated || fm.value.date).valueOf() + const diff = dayjs().valueOf() - updated.value.valueOf() if (typeof fm.value.time_warning === 'number') return diff > fm.value.time_warning else @@ -28,6 +32,6 @@ const time_warning = computed(() => { From c8862175159443c3c5a9fc757b2b4624e3791ba2 Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Fri, 26 Apr 2024 22:42:12 +0800 Subject: [PATCH 2/2] fix(theme yun): insert space when ago starts with number --- .../valaxy-theme-yun/components/YunMdTimeWarning.vue | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/valaxy-theme-yun/components/YunMdTimeWarning.vue b/packages/valaxy-theme-yun/components/YunMdTimeWarning.vue index 4e6d6a653..cf0c78b66 100644 --- a/packages/valaxy-theme-yun/components/YunMdTimeWarning.vue +++ b/packages/valaxy-theme-yun/components/YunMdTimeWarning.vue @@ -17,6 +17,14 @@ const updated = computed(() => { return dayjs(fm.value.updated || fm.value.date) }) +const ago = computed(() => { + const fromNow = updated.value.fromNow() + if (/^\d/.test(fromNow)) + return ` ${fromNow}` + else + return fromNow +}) + /** * when the post is updated more than 180 days ago, show a warning * default 180 days, you can set `time_warning` in frontmatter to change it @@ -32,6 +40,6 @@ const time_warning = computed(() => {