Skip to content

Commit

Permalink
Refactor post filtering logic to exclude drafts and unpublished posts…
Browse files Browse the repository at this point in the history
… in index.astro
  • Loading branch information
zackbraksa committed Dec 17, 2024
1 parent 6fb7cbb commit ed9bf87
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ import convertAsteriskToStrongTag from "@/utils/convertAsteriskToStrongTag";
import presentation from "@/data/presentation";
import projects from "@/data/projects";
const posts = (await getCollection("posts")).sort(function (first, second) {
return second.data.publishedAt.getTime() - first.data.publishedAt.getTime();
});
const posts = (await getCollection("posts"))
.filter((post) =>
post.data.isPublish &&
!post.data.isDraft &&
post.data.publishedAt <= new Date()
)
.sort((first, second) =>
second.data.publishedAt.getTime() - first.data.publishedAt.getTime()
);
---

<Layout>
Expand Down

0 comments on commit ed9bf87

Please sign in to comment.