Skip to content

Commit

Permalink
fix: disable access to draft posts via url
Browse files Browse the repository at this point in the history
  • Loading branch information
satnaing committed Dec 2, 2022
1 parent 19e34a0 commit 1c2821e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/pages/posts/[slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ type PagePaths = {
export async function getStaticPaths() {
const posts = await Astro.glob<Frontmatter>("../../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),
Expand All @@ -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];
}
Expand Down

0 comments on commit 1c2821e

Please sign in to comment.