From b8b7aaef7d7577d107d8679b68c47bd793314e55 Mon Sep 17 00:00:00 2001 From: Sat Naing Date: Thu, 22 Sep 2022 23:36:44 +0630 Subject: [PATCH] Add filter for draft posts --- src/utils/getSortedPosts.ts | 12 +++++++----- src/utils/getUniqueTags.ts | 3 ++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/utils/getSortedPosts.ts b/src/utils/getSortedPosts.ts index 292547b..d38f6a7 100644 --- a/src/utils/getSortedPosts.ts +++ b/src/utils/getSortedPosts.ts @@ -2,10 +2,12 @@ import type { MarkdownInstance } from "astro"; import type { Frontmatter } from "../types"; const getSortedPosts = (posts: MarkdownInstance[]) => - posts.sort( - (a, b) => - Math.floor(new Date(b.frontmatter.datetime).getTime() / 1000) - - Math.floor(new Date(a.frontmatter.datetime).getTime() / 1000) - ); + posts + .filter(({ frontmatter }) => !frontmatter.draft) + .sort( + (a, b) => + Math.floor(new Date(b.frontmatter.datetime).getTime() / 1000) - + Math.floor(new Date(a.frontmatter.datetime).getTime() / 1000) + ); export default getSortedPosts; diff --git a/src/utils/getUniqueTags.ts b/src/utils/getUniqueTags.ts index f4f0641..4e62cfb 100644 --- a/src/utils/getUniqueTags.ts +++ b/src/utils/getUniqueTags.ts @@ -4,7 +4,8 @@ import type { Frontmatter } from "../types"; const getUniqueTags = (posts: MarkdownInstance[]) => { let tags: string[] = []; - posts.forEach((post) => { + const filteredPosts = posts.filter(({ frontmatter }) => !frontmatter.draft); + filteredPosts.forEach((post) => { tags = [...tags, ...post.frontmatter.tags] .map((tag) => slugify(tag)) .filter(