feat: add date formatting component and configuration options

- Add DateFormat and PostTime components, supporting multiple date display formats
- Add dateFormat option in theme configuration, allowing customization of date display styles
- Refactor time display logic in article list and article detail pages
- Update configuration type definitions to support new date format options
This commit is contained in:
radishzzz 2025-03-11 15:33:39 +00:00
parent 4b21e6ee39
commit 8ac9b865f5
7 changed files with 184 additions and 30 deletions

View file

@ -1,5 +1,6 @@
---
// Define props received by the component
import PostTime from '@/components/PostTime.astro'
interface Post {
data: {
title: string
@ -31,9 +32,9 @@ function getPostUrl(post: Post) {
---
<ul>
{posts.map(post => (
// Single Post
<li class="mt-4.375">
{/* post title */}
<a
class="hover:c-primary"
href={getPostUrl(post)}
@ -43,26 +44,24 @@ function getPostUrl(post: Post) {
{post.data.title}
</a>
{/* mobile post time */}
<div
class="uno-mobile-time"
transition:name={`time-${post.data.abbrlink || post.slug}`}
data-disable-transition-on-theme
>
<time>
{post.data.published.toLocaleDateString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '-')}
</time>
<span class="ml-1.25">
{post.remarkPluginFrontmatter?.minutes} min
</span>
<PostTime
date={post.data.published}
minutes={post.remarkPluginFrontmatter?.minutes}
/>
</div>
{/* desktop post time */}
<div class="uno-desktop-time">
<time>
{post.data.published.toLocaleDateString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '-')}
</time>
<span class="ml-1.25">
{post.remarkPluginFrontmatter?.minutes} min
</span>
<PostTime
date={post.data.published}
minutes={post.remarkPluginFrontmatter?.minutes}
/>
</div>
</li>