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,
|
||||
title: 'Hello, BlogFlare! (Fallback)',
|
||||
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'
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
title: 'The Beauty of Typecho Theme VOID',
|
||||
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'
|
||||
}
|
||||
]
|
||||
@@ -33,10 +33,16 @@ export const load: PageServerLoad = async ({ platform }) => {
|
||||
).all();
|
||||
|
||||
// Convert date to string for serialization
|
||||
const formattedPosts = results.map(post => ({
|
||||
...post,
|
||||
date: new Date(post.date as string).toLocaleDateString()
|
||||
}));
|
||||
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,
|
||||
date: `${month} ${day}, ${year}`
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
posts: formattedPosts
|
||||
|
||||
+10
-10
@@ -6,17 +6,17 @@
|
||||
<section id="index-list">
|
||||
<div class="post-list">
|
||||
{#each data.posts as post}
|
||||
<article class="card yue">
|
||||
<div class="content-wrap">
|
||||
<div class="post-meta-index">
|
||||
<time>{post.date}</time>
|
||||
</div>
|
||||
<a href="/posts/{post.slug}">
|
||||
<a href="/posts/{post.slug}" class="card-link">
|
||||
<article class="card article-content">
|
||||
<div class="content-wrap">
|
||||
<div class="post-meta-index">
|
||||
<time>{post.date}</time>
|
||||
</div>
|
||||
<h1 class="title">{post.title}</h1>
|
||||
</a>
|
||||
<p class="headline">{post.excerpt}</p>
|
||||
</div>
|
||||
</article>
|
||||
<p class="excerpt">{post.excerpt} | <span class="full-link">阅读全文</span></p>
|
||||
</div>
|
||||
</article>
|
||||
</a>
|
||||
{/each}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
Reference in new issue
Block a user