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) {