Skip to content

Commit

Permalink
fix: md time warning locale & add test
Browse files Browse the repository at this point in the history
  • Loading branch information
YunYouJun committed Jan 1, 2025
1 parent 992c6c2 commit 2d94ef9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion demo/yun/locales/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ excerpt:
ai: 由 AI 生成的摘要

post:
time_warning: '本文最后更新于{ago},文中所描述的信息可能已发生改变。(覆盖测试)'
time_warning: '本文最后更新于 {ago},文中所描述的信息可能已发生改变。(覆盖测试)'
7 changes: 6 additions & 1 deletion e2e/theme-yun/fm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ test.describe('Frontmatter', () => {

test('time warning', async ({ page }) => {
await page.goto('/test/time_warning')

await expect(page.locator('.yun-time-warning')).toHaveCount(1)

// Post Updated
await page.goto('/posts/post-updated')
// locale override
// 正则表达式匹配
await expect(page.locator('.yun-time-warning')).toHaveText(/^(.*)$/)
})

test('word count & reading time', async ({ page }) => {
Expand Down
12 changes: 3 additions & 9 deletions packages/valaxy-theme-yun/components/YunMdTimeWarning.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,13 @@ import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
const fm = useFrontmatter()
const { t } = useI18n()
const { t, locale } = useI18n()
const updated = computed(() => {
return dayjs(fm.value.updated || fm.value.date)
return dayjs(fm.value.updated || fm.value.date).locale(locale.value)
})
const ago = computed(() => {
const fromNow = updated.value.fromNow()
if (/^\d/.test(fromNow))
return ` ${fromNow}`
else
return fromNow
})
const ago = computed(() => updated.value.fromNow())
/**
* when the post is updated more than 180 days ago, show a warning
Expand Down

1 comment on commit 2d94ef9

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Published on https://yun.valaxy.site as production
🚀 Deployed on https://677548bd8b0d23c1b53b1d74--valaxy.netlify.app

Please sign in to comment.