Skip to content

Commit

Permalink
fix: update the posts to handle featured posts; fix date
Browse files Browse the repository at this point in the history
  • Loading branch information
ericrallen committed Apr 12, 2024
1 parent 8e7d6a4 commit 07364ac
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion _posts/hello-world.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Hello, World!
date: 2023-03-02
date: 2024-03-02
excerpt: DVDA Games is part wannabe indie game studio and part open-source tool
developer.
coverImage: /assets/blog/hello-world/cover.jpg
Expand All @@ -10,6 +10,7 @@ author:
ogImage:
url: /assets/blog/hello-world/cover.jpg
preview: false
featured: true
---
Dead Villager Dead Adventurer (DVDA) Games is named for those fallen souls in the [Diablo games](https://en.wikipedia.org/wiki/Diablo_%28video_game%29) who gave their lives in pursuit of adventure or were just unfortunate enough to encounter the horrors outside of the relative safety of the town.

Expand Down
1 change: 1 addition & 0 deletions src/interfaces/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export type Post = {
};
content: string;
preview?: boolean;
featured?: boolean;
};
10 changes: 9 additions & 1 deletion src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,17 @@ export function getPostBySlug(slug: string) {

export function getAllPosts(): Post[] {
const slugs = getPostSlugs();

const featuredPosts = slugs
.map((slug) => getPostBySlug(slug))
.filter((post) => post.featured)
.sort((post1, post2) => (post1.date > post2.date ? -1 : 1));

const posts = slugs
.map((slug) => getPostBySlug(slug))
.filter((post) => !post.featured)
// sort posts by date in descending order
.sort((post1, post2) => (post1.date > post2.date ? -1 : 1));
return posts;

return [...featuredPosts, ...posts];
}

0 comments on commit 07364ac

Please sign in to comment.