From 67109ae7fe3b35ca21b9b0aa0bc1b24d1d3cf211 Mon Sep 17 00:00:00 2001 From: Yufan Sheng Date: Thu, 28 Nov 2024 01:47:25 +0800 Subject: [PATCH] chore: better display the article date. --- src/components/comment/CommentItem.astro | 2 +- src/helpers/formatter.ts | 7 +++++-- src/layouts/PostLayout.astro | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/components/comment/CommentItem.astro b/src/components/comment/CommentItem.astro index 5612bb9..7227bfc 100644 --- a/src/components/comment/CommentItem.astro +++ b/src/components/comment/CommentItem.astro @@ -50,7 +50,7 @@ const { comment, depth, pending } = Astro.props; {pending &&

您的评论正在等待审核中...

} diff --git a/src/helpers/formatter.ts b/src/helpers/formatter.ts index 1e5eaf6..0588710 100644 --- a/src/helpers/formatter.ts +++ b/src/helpers/formatter.ts @@ -61,7 +61,10 @@ export const formatShowDate = (date: Date) => { .toFormat(options.settings.timeFormat); }; -export const formatLocalDate = (source: string) => { +export const formatLocalDate = (source: string | Date, format?: string) => { const date = new Date(source); - return DateTime.fromJSDate(date).setLocale(options.settings.locale).toFormat(options.settings.timeFormat); + return DateTime.fromJSDate(date) + .setZone(options.settings.timeZone) + .setLocale(options.settings.locale) + .toFormat(format || options.settings.timeFormat); }; diff --git a/src/layouts/PostLayout.astro b/src/layouts/PostLayout.astro index 1ea5a79..cad7edf 100644 --- a/src/layouts/PostLayout.astro +++ b/src/layouts/PostLayout.astro @@ -7,7 +7,7 @@ import PostMeta from '@/components/meta/PostMeta.astro'; import TableOfContents from '@/components/page/toc/TableOfContents.astro'; import MusicPlayer from '@/components/player/MusicPlayer.astro'; import Sidebar from '@/components/sidebar/Sidebar.astro'; -import { formatShowDate } from '@/helpers/formatter'; +import { formatLocalDate } from '@/helpers/formatter'; import { getTag, posts, tags, type Post } from '@/helpers/schema'; import { urlJoin } from '@/helpers/tools'; import BaseLayout from '@/layouts/BaseLayout.astro'; @@ -39,7 +39,7 @@ const { Content, headings } = await post.render();

{post.title}