Skip to content

Commit

Permalink
Prevent from rendering draft posts
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp committed Jun 20, 2022
1 parent e47dfb5 commit 2dc17d0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/astro/src/core/build/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ function* throttle(max: number, inPaths: string[]) {
}
}

function shouldSkipDraft(pageModule: ComponentInstance, astroConfig: AstroConfig): boolean {
return (
// Drafts are disabled
!astroConfig.markdown.drafts &&
// This is a draft post
('frontmatter' in pageModule && (pageModule as any).frontmatter.draft === true)
);
}

// Gives back a facadeId that is relative to the root.
// ie, src/pages/index.astro instead of /Users/name..../src/pages/index.astro
export function rootRelativeFacadeId(facadeId: string, astroConfig: AstroConfig): string {
Expand Down Expand Up @@ -124,6 +133,11 @@ async function generatePage(
);
}

if(shouldSkipDraft(pageModule, opts.astroConfig)) {
info(opts.logging, null, `${magenta('⚠️')} Skipping draft ${pageData.route.component}`);
return;
}

const generationOptions: Readonly<GeneratePathOptions> = {
pageData,
internals,
Expand Down

0 comments on commit 2dc17d0

Please sign in to comment.