use the preprocessor to detect if it's a draft instead.
This commit is contained in:
parent
1cd021d0a7
commit
08db74793e
|
@ -1,53 +0,0 @@
|
||||||
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;
|
|
||||||
});
|
|
||||||
}
|
|
|
@ -11,8 +11,6 @@ import pluginNavigation from "@11ty/eleventy-navigation";
|
||||||
import { EleventyHtmlBasePlugin } from "@11ty/eleventy";
|
import { EleventyHtmlBasePlugin } from "@11ty/eleventy";
|
||||||
import { eleventyImageTransformPlugin } from "@11ty/eleventy-img";
|
import { eleventyImageTransformPlugin } from "@11ty/eleventy-img";
|
||||||
|
|
||||||
import pluginDrafts from "./eleventy.config.drafts.js";
|
|
||||||
|
|
||||||
import fs from "fs/promises";
|
import fs from "fs/promises";
|
||||||
|
|
||||||
/** @param {import('@11ty/eleventy').UserConfig} eleventyConfig */
|
/** @param {import('@11ty/eleventy').UserConfig} eleventyConfig */
|
||||||
|
@ -28,7 +26,11 @@ export default async function (eleventyConfig) {
|
||||||
eleventyConfig.addWatchTarget("content/**/*.{svg,webp,png,jpeg}");
|
eleventyConfig.addWatchTarget("content/**/*.{svg,webp,png,jpeg}");
|
||||||
|
|
||||||
// App plugins
|
// App plugins
|
||||||
eleventyConfig.addPlugin(pluginDrafts);
|
eleventyConfig.addPreprocessor("drafts", "*", (data, _content) => {
|
||||||
|
if(data.draft && process.env.ELEVENTY_RUN_MODE === "build") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
// eleventyConfig.addPlugin(pluginFonts);
|
// eleventyConfig.addPlugin(pluginFonts);
|
||||||
// Official plugins
|
// Official plugins
|
||||||
let mkFeed = function (type, path) {
|
let mkFeed = function (type, path) {
|
||||||
|
|
Loading…
Reference in a new issue