From 2dc17d0fae218dc521c8e843244156540ccad431 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 20 Jun 2022 15:32:07 -0400 Subject: [PATCH] Prevent from rendering draft posts --- packages/astro/src/core/build/generate.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index 65f3930dd975..469d04c501b4 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -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 { @@ -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 = { pageData, internals,