feat: 更新文章列表布局与日期格式化逻辑
This commit is contained in:
1 parent
ca307ea9c9
commit
94da2091e7
2 files changed
+22
-16
No files matched your search
@@ -11,14 +11,14 @@ export const load: PageServerLoad = async ({ platform }) => {
|
|||||||
id: 1,
|
id: 1,
|
||||||
title: 'Hello, BlogFlare! (Fallback)',
|
title: 'Hello, BlogFlare! (Fallback)',
|
||||||
excerpt: 'This is my first post on BlogFlare. Welcome to my new blog powered by SvelteKit.',
|
excerpt: 'This is my first post on BlogFlare. Welcome to my new blog powered by SvelteKit.',
|
||||||
date: '2026-07-12',
|
date: 'Jul 12, 2026',
|
||||||
slug: 'hello-world'
|
slug: 'hello-world'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 2,
|
id: 2,
|
||||||
title: 'The Beauty of Typecho Theme VOID',
|
title: 'The Beauty of Typecho Theme VOID',
|
||||||
excerpt: 'VOID is a minimalist, typography-oriented theme that brings elegance to your reading experience.',
|
excerpt: 'VOID is a minimalist, typography-oriented theme that brings elegance to your reading experience.',
|
||||||
date: '2026-07-11',
|
date: 'Jul 11, 2026',
|
||||||
slug: 'beauty-of-void'
|
slug: 'beauty-of-void'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -33,10 +33,16 @@ export const load: PageServerLoad = async ({ platform }) => {
|
|||||||
).all();
|
).all();
|
||||||
|
|
||||||
// Convert date to string for serialization
|
// Convert date to string for serialization
|
||||||
const formattedPosts = results.map(post => ({
|
const formattedPosts = results.map(post => {
|
||||||
...post,
|
const d = new Date(post.date as string);
|
||||||
date: new Date(post.date as string).toLocaleDateString()
|
const month = d.toLocaleString('en-US', { month: 'short' });
|
||||||
}));
|
const day = d.getDate();
|
||||||
|
const year = d.getFullYear();
|
||||||
|
return {
|
||||||
|
...post,
|
||||||
|
date: `${month} ${day}, ${year}`
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
posts: formattedPosts
|
posts: formattedPosts
|
||||||
|
|||||||
+10
-10
@@ -6,17 +6,17 @@
|
|||||||
<section id="index-list">
|
<section id="index-list">
|
||||||
<div class="post-list">
|
<div class="post-list">
|
||||||
{#each data.posts as post}
|
{#each data.posts as post}
|
||||||
<article class="card yue">
|
<a href="/posts/{post.slug}" class="card-link">
|
||||||
<div class="content-wrap">
|
<article class="card article-content">
|
||||||
<div class="post-meta-index">
|
<div class="content-wrap">
|
||||||
<time>{post.date}</time>
|
<div class="post-meta-index">
|
||||||
</div>
|
<time>{post.date}</time>
|
||||||
<a href="/posts/{post.slug}">
|
</div>
|
||||||
<h1 class="title">{post.title}</h1>
|
<h1 class="title">{post.title}</h1>
|
||||||
</a>
|
<p class="excerpt">{post.excerpt} | <span class="full-link">阅读全文</span></p>
|
||||||
<p class="headline">{post.excerpt}</p>
|
</div>
|
||||||
</div>
|
</article>
|
||||||
</article>
|
</a>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
Reference in new issue
Block a user