feat: 更新文章列表布局与日期格式化逻辑

This commit is contained in:
seahi committed 2026-07-16 19:32:39 +08:00
1 parent ca307ea9c9
commit 94da2091e7
2 files changed
+15 -9

No files matched your search

+11 -5
View File
@@ -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 => {
const d = new Date(post.date as string);
const month = d.toLocaleString('en-US', { month: 'short' });
const day = d.getDate();
const year = d.getFullYear();
return {
...post, ...post,
date: new Date(post.date as string).toLocaleDateString() date: `${month} ${day}, ${year}`
})); };
});
return { return {
posts: formattedPosts posts: formattedPosts
+4 -4
View File
@@ -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">
<article class="card article-content">
<div class="content-wrap"> <div class="content-wrap">
<div class="post-meta-index"> <div class="post-meta-index">
<time>{post.date}</time> <time>{post.date}</time>
</div> </div>
<a href="/posts/{post.slug}">
<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>