From 1c2821e4df65bee7126aed17244bb6590b1163d8 Mon Sep 17 00:00:00 2001 From: satnaing Date: Fri, 2 Dec 2022 23:28:45 +0630 Subject: [PATCH] fix: disable access to draft posts via url --- src/pages/posts/[slug].astro | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/pages/posts/[slug].astro b/src/pages/posts/[slug].astro index c19533ae8..7976f4955 100644 --- a/src/pages/posts/[slug].astro +++ b/src/pages/posts/[slug].astro @@ -30,7 +30,9 @@ type PagePaths = { export async function getStaticPaths() { const posts = await Astro.glob("../../contents/**/*.md"); - let postResult: PostResult = posts.map(post => { + const filteredPosts = posts.filter(({ frontmatter }) => !frontmatter.draft); + + let postResult: PostResult = filteredPosts.map(post => { return { params: { slug: slugify(post.frontmatter), @@ -41,9 +43,11 @@ export async function getStaticPaths() { }; }); - const pagePaths: PagePaths = getPageNumbers(posts.length).map(pageNum => ({ - params: { slug: String(pageNum) }, - })); + const pagePaths: PagePaths = getPageNumbers(filteredPosts.length).map( + pageNum => ({ + params: { slug: String(pageNum) }, + }) + ); return [...postResult, ...pagePaths]; }