chore: better display the article date.

This commit is contained in:
Yufan Sheng 2024-11-28 01:47:25 +08:00
parent 727beb2e4e
commit 67109ae7fe
Signed by: syhily
GPG Key ID: DEB186763C308C31
3 changed files with 8 additions and 5 deletions

View File

@ -50,7 +50,7 @@ const { comment, depth, pending } = Astro.props;
{pending && <p class="text-xs text-danger tip-comment-check">您的评论正在等待审核中...</p>} {pending && <p class="text-xs text-danger tip-comment-check">您的评论正在等待审核中...</p>}
</div> </div>
<div class="comment-footer text-xs text-muted"> <div class="comment-footer text-xs text-muted">
<time class="me-2">{formatLocalDate(comment.date)}</time> <time class="me-2">{formatLocalDate(comment.date, 'yyyy-MM-dd HH:mm')}</time>
<button class="comment-reply-link" data-rid={comment.id}>回复</button> <button class="comment-reply-link" data-rid={comment.id}>回复</button>
</div> </div>
</div> </div>

View File

@ -61,7 +61,10 @@ export const formatShowDate = (date: Date) => {
.toFormat(options.settings.timeFormat); .toFormat(options.settings.timeFormat);
}; };
export const formatLocalDate = (source: string) => { export const formatLocalDate = (source: string | Date, format?: string) => {
const date = new Date(source); 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);
}; };

View File

@ -7,7 +7,7 @@ import PostMeta from '@/components/meta/PostMeta.astro';
import TableOfContents from '@/components/page/toc/TableOfContents.astro'; import TableOfContents from '@/components/page/toc/TableOfContents.astro';
import MusicPlayer from '@/components/player/MusicPlayer.astro'; import MusicPlayer from '@/components/player/MusicPlayer.astro';
import Sidebar from '@/components/sidebar/Sidebar.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 { getTag, posts, tags, type Post } from '@/helpers/schema';
import { urlJoin } from '@/helpers/tools'; import { urlJoin } from '@/helpers/tools';
import BaseLayout from '@/layouts/BaseLayout.astro'; import BaseLayout from '@/layouts/BaseLayout.astro';
@ -39,7 +39,7 @@ const { Content, headings } = await post.render();
<div class="card-body"> <div class="card-body">
<h1 class="post-title">{post.title}</h1> <h1 class="post-title">{post.title}</h1>
<div class="post-meta text-sm text-muted mt-3 mb-4"> <div class="post-meta text-sm text-muted mt-3 mb-4">
<time class="">{formatShowDate(post.date)}</time> <time class="">{formatLocalDate(post.date, 'yyyy-MM-dd HH:mm')}</time>
{ {
post.tags.length > 0 && post.tags.length > 0 &&
post.tags post.tags