2023-07-13 17:23:04 +00: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-07-13 17:31:01 +00:00
|
|
|
if(data.draft && process.env.BUILD_DRAFTS != "true") {
|
2023-07-13 17:23:04 +00: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-07-13 17:31:01 +00:00
|
|
|
if(data.draft && process.env.BUILD_DRAFTS != "true") {
|
2023-07-13 17:23:04 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return data.eleventyExcludeFromCollections;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports.eleventyComputedPermalink = eleventyComputedPermalink;
|
|
|
|
module.exports.eleventyComputedExcludeFromCollections = eleventyComputedExcludeFromCollections;
|
|
|
|
|
|
|
|
module.exports = eleventyConfig => {
|
|
|
|
eleventyConfig.addGlobalData("eleventyComputed.permalink", eleventyComputedPermalink);
|
|
|
|
eleventyConfig.addGlobalData("eleventyComputed.eleventyExcludeFromCollections", eleventyComputedExcludeFromCollections);
|
|
|
|
|
|
|
|
let logged = false;
|
|
|
|
eleventyConfig.on("eleventy.before", ({runMode}) => {
|
|
|
|
let text = "Excluding";
|
|
|
|
|
|
|
|
if(process.env.BUILD_DRAFTS == "true") {
|
|
|
|
text = "Including";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only log once.
|
|
|
|
if(!logged) {
|
|
|
|
console.log( `[11ty/drafts] ${text} drafts.` );
|
|
|
|
}
|
|
|
|
|
|
|
|
logged = true;
|
|
|
|
});
|
|
|
|
}
|