Skip to content

Commit 2dfe91b

Browse files
committed
order articles in homepage by latest
1 parent cead851 commit 2dfe91b

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/routes/(home)/+page.server.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import { fetchMarkdownPosts } from '$lib/utils/index_posts';
33

44
export async function load() {
55
const allPosts = await fetchMarkdownPosts();
6-
const posts = allPosts.slice(0, 6);
6+
7+
const posts = allPosts
8+
.sort((a, b) => new Date(b.meta.date).getTime() - new Date(a.meta.date).getTime())
9+
.slice(0, 6);
710

811
return {
912
features,

src/routes/blog/[slug]/+page.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@
5656
<h2>Related Posts:</h2>
5757
<div class="grid">
5858
{#each data.posts.slice(0, 3) as post}
59-
<BlogPreview post_data={post.meta} />
59+
<a href={post.path}>
60+
<BlogPreview post_data={post.meta} />
61+
</a>
6062
{/each}
6163
</div>
6264
</div>

0 commit comments

Comments
 (0)