diff --git a/demo/yun/components/test/TestFormatDate.vue b/demo/yun/components/test/TestFormatDate.vue new file mode 100644 index 000000000..cf7204d1c --- /dev/null +++ b/demo/yun/components/test/TestFormatDate.vue @@ -0,0 +1,18 @@ + + + diff --git a/demo/yun/pages/posts/date.md b/demo/yun/pages/posts/date.md index 5a0159ece..36d8b526c 100644 --- a/demo/yun/pages/posts/date.md +++ b/demo/yun/pages/posts/date.md @@ -2,4 +2,73 @@ title: Date test date: 2023-07-19 18:55:53 # updated: 2023-07-19 18:55:53 +toc: false --- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demo/yun/site.config.ts b/demo/yun/site.config.ts index cdafa2025..352fc961f 100644 --- a/demo/yun/site.config.ts +++ b/demo/yun/site.config.ts @@ -7,6 +7,7 @@ export default defineSiteConfig({ lang: 'zh-CN', title: 'Valaxy Theme Yun', + timezone: 'Asia/Shanghai', url: 'https://yun.valaxy.site/', author: { avatar: 'https://www.yunyoujun.cn/images/avatar.jpg', diff --git a/docs/pages/faq/index.md b/docs/pages/faq/index.md index c6917b0b1..6829c6238 100644 --- a/docs/pages/faq/index.md +++ b/docs/pages/faq/index.md @@ -71,51 +71,3 @@ So you can create a new file named `.nojekyll` in the `public` folder of the pro |-- public | |-- .nojekyll ``` - -## 显示的文章创建/修改时间不正确 {lang="zh-CN"} - -## The displayed article creation/modification time is incorrect {lang="en"} - -::: zh-CN -根据[这份 `YAML` 规范](https://yaml.org/type/timestamp.html),符合 `ISO 8601` 标准的时间格式都会被解析为 `Date` 类型,且**不显式标注时区的时间戳都会作 UTC 处理**。 - -但是为了方便写作与从其他框架迁移,我们将未显式标注时区的时间戳解析为**系统时区**对应的时间(即 `2024-07-06 12:00:00` 在 `Asia/Shanghai` 下会解析 为 `2024-07-06T12:00:00+08:00`)。 - -无论如何,我们建议**显式**添加时区信息,例如: - -```yaml -date: 2024-07-06 12:00:00 +8 -``` - -如果你不喜欢显式标记,请**务必**在构建前指定系统时区: - -```bash -sudo timedatectl set-timezone Asia/Shanghai -``` - -这样就能正确解析为 UTC+8 时区的 `2024-07-06 12:00:00`。 - -主题作者也能通过在 `scaffolds/post.md` 中使用 `date: <%=date%> +8` 来实现这一点。 -::: - -::: en -According to [this `YAML` specification](https://yaml.org/type/timestamp.html), time formats that conform to the `ISO 8601` standard will be parsed as `Date` type, and **timestamps without explicitly marked time zones will be treated as UTC**. - -However, for the convenience of writing and migrating from other frameworks, we parse timestamps without explicitly marked timezones under system timezone (i.e., `2024-07-06 12:00:00` will be parsed as `2024-07-06T12:00:00+08:00` in `Asia/Shanghai`). - -If you don't like explicit marking, **be sure** to specify the system time zone before building: - -```bash -sudo timedatectl set-timezone Asia/Shanghai -``` - -Nevertheless, we recommend **explicitly** adding time zone information, for example: - -```yaml -date: 2024-07-06 12:00:00 +8 -``` - -This way, it can be correctly parsed as `2024-07-06 12:00:00` in the UTC+8 time zone. - -Theme authors can also achieve this by using `date: <%=date%> +8` in `scaffolds/post.md`. -::: diff --git a/e2e/theme-yun/time.spec.ts b/e2e/theme-yun/time.spec.ts new file mode 100644 index 000000000..0aa3d24fd --- /dev/null +++ b/e2e/theme-yun/time.spec.ts @@ -0,0 +1,30 @@ +import { expect, test } from '@playwright/test' +import { env } from '../env' + +test.use({ + baseURL: env['theme-yun'], +}) + +test.beforeEach(async ({ page }) => { + await page.goto('/posts/date') +}) + +test.describe('Frontmatter', () => { + test('time format validation', async ({ page }) => { + await expect(page.locator('#text-time-format-1 time')).toHaveText('20230719') + await expect(page.locator('#text-time-format-2 time')).toHaveText('20210301120000') + await expect(page.locator('#text-time-format-3 time')).toHaveText('2021/12/03 01:07') + }) + + test('timezone format validation', async ({ page }) => { + await expect(page.locator('#text-time-zone-1 time')).toHaveText('2004-06-15 18:00:00+02:00 GMT+2') + await expect(page.locator('#text-time-zone-2 time')).toHaveText('2004-06-15 18:00:00+02:00 GMT+2') + await expect(page.locator('#text-time-zone-3 time')).toHaveText('2004-06-16 00:00:00+08:00 GMT+8') + await expect(page.locator('#text-time-zone-4 time')).toHaveText('2004-06-16 02:00:00+02:00 GMT+2') + await expect(page.locator('#text-time-zone-5 time')).toHaveText('2004-06-15 23:00:00+07:00 GMT+7') + await expect(page.locator('#text-time-zone-6 time')).toHaveText('2004-06-16 06:00:00+08:00 GMT+8') + await expect(page.locator('#text-time-zone-6 time')).toHaveText('2004-06-16 06:00:00+08:00 GMT+8') + await expect(page.locator('#text-time-zone-7 time')).toHaveText('2004-06-16 00:00:00+02:00 GMT+2') + await expect(page.locator('#text-time-zone-8 time')).toHaveText('2004-06-16 08:00:00+08:00 GMT+8') + }) +}) diff --git a/packages/valaxy-theme-yun/components/YunPostMeta.vue b/packages/valaxy-theme-yun/components/YunPostMeta.vue index b1cf9e994..1610ac801 100644 --- a/packages/valaxy-theme-yun/components/YunPostMeta.vue +++ b/packages/valaxy-theme-yun/components/YunPostMeta.vue @@ -1,7 +1,8 @@