Skip to content

Commit 2d94ef9

Browse files
committed
fix: md time warning locale & add test
1 parent 992c6c2 commit 2d94ef9

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

demo/yun/locales/zh-CN.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ excerpt:
55
ai: 由 AI 生成的摘要
66

77
post:
8-
time_warning: '本文最后更新于{ago},文中所描述的信息可能已发生改变。(覆盖测试)'
8+
time_warning: '本文最后更新于 {ago},文中所描述的信息可能已发生改变。(覆盖测试)'

e2e/theme-yun/fm.spec.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ test.describe('Frontmatter', () => {
2121

2222
test('time warning', async ({ page }) => {
2323
await page.goto('/test/time_warning')
24-
2524
await expect(page.locator('.yun-time-warning')).toHaveCount(1)
25+
26+
// Post Updated
27+
await page.goto('/posts/post-updated')
28+
// locale override
29+
// 正则表达式匹配
30+
await expect(page.locator('.yun-time-warning')).toHaveText(/^(.*)$/)
2631
})
2732

2833
test('word count & reading time', async ({ page }) => {

packages/valaxy-theme-yun/components/YunMdTimeWarning.vue

+3-9
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,13 @@ import { computed } from 'vue'
55
import { useI18n } from 'vue-i18n'
66
77
const fm = useFrontmatter()
8-
const { t } = useI18n()
8+
const { t, locale } = useI18n()
99
1010
const updated = computed(() => {
11-
return dayjs(fm.value.updated || fm.value.date)
11+
return dayjs(fm.value.updated || fm.value.date).locale(locale.value)
1212
})
1313
14-
const ago = computed(() => {
15-
const fromNow = updated.value.fromNow()
16-
if (/^\d/.test(fromNow))
17-
return ` ${fromNow}`
18-
else
19-
return fromNow
20-
})
14+
const ago = computed(() => updated.value.fromNow())
2115
2216
/**
2317
* when the post is updated more than 180 days ago, show a warning

0 commit comments

Comments
 (0)