adapt interpretation of config default value for buildOptions.draft
adds logic for collections
This commit is contained in:
parent
cba4f2bd5c
commit
271b45f16b
2 changed files with 6 additions and 2 deletions
|
@ -66,7 +66,7 @@ function configDefaults(userConfig?: any): any {
|
||||||
if (!config.buildOptions) config.buildOptions = {};
|
if (!config.buildOptions) config.buildOptions = {};
|
||||||
if (!config.markdownOptions) config.markdownOptions = {};
|
if (!config.markdownOptions) config.markdownOptions = {};
|
||||||
if (typeof config.buildOptions.sitemap === 'undefined') config.buildOptions.sitemap = true;
|
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;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,7 @@ async function load(config: RuntimeConfig, rawPathname: string | undefined): Pro
|
||||||
error: new Error('Unpublished document')
|
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 {
|
return {
|
||||||
statusCode: 404,
|
statusCode: 404,
|
||||||
error: new Error('Unpublished document')
|
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 });
|
let data: any[] = await loadData({ params: currentParams });
|
||||||
if (!data) throw new Error(`[createCollection] \`data()\` returned nothing (empty data)"`);
|
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?
|
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
|
// handle RSS
|
||||||
if (createRSS) {
|
if (createRSS) {
|
||||||
|
|
Loading…
Reference in a new issue