2023-01-24 09:08:52 -05:00
|
|
|
function eleventyComputedPermalink() {
|
|
|
|
// When using `addGlobalData` and you *want* to return a function, you must nest functions like this.
|
|
|
|
// `addGlobalData` acts like a global data file and runs the top level function it receives.
|
|
|
|
return (data) => {
|
2023-01-24 16:32:58 -05:00
|
|
|
// Always skip during non-watch/serve builds
|
|
|
|
if(data.draft && !process.env.BUILD_DRAFTS) {
|
2023-01-24 09:08:52 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return data.permalink;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function eleventyComputedExcludeFromCollections() {
|
|
|
|
// When using `addGlobalData` and you *want* to return a function, you must nest functions like this.
|
|
|
|
// `addGlobalData` acts like a global data file and runs the top level function it receives.
|
|
|
|
return (data) => {
|
2023-01-24 16:32:58 -05:00
|
|
|
// Always exclude from non-watch/serve builds
|
|
|
|
if(data.draft && !process.env.BUILD_DRAFTS) {
|
2023-01-24 09:08:52 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return data.eleventyExcludeFromCollections;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-11-10 17:41:13 -05:00
|
|
|
export { eleventyComputedPermalink, eleventyComputedExcludeFromCollections };
|
2023-01-24 09:08:52 -05:00
|
|
|
|
2023-11-10 17:41:13 -05:00
|
|
|
export default function(eleventyConfig) {
|
2023-01-24 09:08:52 -05:00
|
|
|
eleventyConfig.addGlobalData("eleventyComputed.permalink", eleventyComputedPermalink);
|
|
|
|
eleventyConfig.addGlobalData("eleventyComputed.eleventyExcludeFromCollections", eleventyComputedExcludeFromCollections);
|
|
|
|
|
|
|
|
let logged = false;
|
|
|
|
eleventyConfig.on("eleventy.before", ({runMode}) => {
|
|
|
|
let text = "Excluding";
|
|
|
|
// Only show drafts in serve/watch modes
|
|
|
|
if(runMode === "serve" || runMode === "watch") {
|
|
|
|
process.env.BUILD_DRAFTS = true;
|
|
|
|
text = "Including";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only log once.
|
|
|
|
if(!logged) {
|
|
|
|
console.log( `[11ty/eleventy-base-blog] ${text} drafts.` );
|
|
|
|
}
|
|
|
|
|
|
|
|
logged = true;
|
|
|
|
});
|
|
|
|
}
|