From 271b45f16b2ce4706c3fd324b4bfb5aedee52036 Mon Sep 17 00:00:00 2001 From: ewatch Date: Wed, 23 Jun 2021 00:12:32 +0200 Subject: [PATCH] adapt interpretation of config default value for buildOptions.draft adds logic for collections --- packages/astro/src/config.ts | 2 +- packages/astro/src/runtime.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/astro/src/config.ts b/packages/astro/src/config.ts index 750d73efe..3dde8f632 100644 --- a/packages/astro/src/config.ts +++ b/packages/astro/src/config.ts @@ -66,7 +66,7 @@ function configDefaults(userConfig?: any): any { if (!config.buildOptions) config.buildOptions = {}; if (!config.markdownOptions) config.markdownOptions = {}; if (typeof config.buildOptions.sitemap === 'undefined') config.buildOptions.sitemap = true; - if (typeof config.buildOptions.draft === 'undefined') config.buildOptions.draft = true; + if (typeof config.buildOptions.draft === 'undefined') config.buildOptions.draft = false; return config; } diff --git a/packages/astro/src/runtime.ts b/packages/astro/src/runtime.ts index 18a46e781..6909dce77 100644 --- a/packages/astro/src/runtime.ts +++ b/packages/astro/src/runtime.ts @@ -114,7 +114,7 @@ async function load(config: RuntimeConfig, rawPathname: string | undefined): Pro error: new Error('Unpublished document') }; } - if(hasDraftAttribute && mod.exports.__content['draft'] === true && buildOptions.draft && config.mode === 'production') { + if(hasDraftAttribute && mod.exports.__content['draft'] === true && !buildOptions.draft && config.mode === 'production') { return { statusCode: 404, error: new Error('Unpublished document') @@ -154,6 +154,10 @@ async function load(config: RuntimeConfig, rawPathname: string | undefined): Pro let data: any[] = await loadData({ params: currentParams }); if (!data) throw new Error(`[createCollection] \`data()\` returned nothing (empty data)"`); if (!Array.isArray(data)) data = [data]; // note: this is supposed to be a little friendlier to the user, but should we error out instead? + data = data.filter(entry => !entry.hasOwnProperty('published') || (entry.hasOwnProperty('published') && entry.published)); + if(!buildOptions.draft && config.mode === "production") { + data = data.filter(entry => !entry.hasOwnProperty('draft') || (entry.hasOwnProperty('draft') && !entry.draft)); + } // handle RSS if (createRSS) {