1
0
Fork 0
blog/eleventy.config.drafts.js
Saji 1cd021d0a7
All checks were successful
Build Blog / Build (push) Successful in 5m32s
lint
2025-05-02 22:38:37 -05:00

54 lines
1.6 KiB
JavaScript

export 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) => {
// Always skip during non-watch/serve builds
if (data.draft && !process.env.BUILD_DRAFTS) {
return false;
}
return data.permalink;
};
}
export 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) => {
// Always exclude from non-watch/serve builds
if (data.draft && !process.env.BUILD_DRAFTS) {
return true;
}
return data.eleventyExcludeFromCollections;
};
}
export default function (eleventyConfig) {
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;
});
}