From 2dbf6d816b15de42db8554974b77cb566df23d26 Mon Sep 17 00:00:00 2001 From: Nicholas Lamicela Date: Fri, 13 Dec 2024 19:27:59 -0800 Subject: [PATCH] fix drafts --- content/blog/draft.md | 19 ++++++++++++++ eleventy.config.drafts.js | 52 --------------------------------------- eleventy.config.js | 14 +++++++---- 3 files changed, 28 insertions(+), 57 deletions(-) create mode 100644 content/blog/draft.md delete mode 100644 eleventy.config.drafts.js diff --git a/content/blog/draft.md b/content/blog/draft.md new file mode 100644 index 0000000..8e7841f --- /dev/null +++ b/content/blog/draft.md @@ -0,0 +1,19 @@ +--- +date: 2024-12-05 +title: draft +description: A can opener is a service component that affords access to preserved fruits and vegetables. +tags: + - language + - programming +draft: true +--- + +If I ask you what a can opener is, and you say + +> A can opener is a service component that affords access to preserved fruits and vegetables. + +This does not help me at all. I am looking for something along the lines of + +> A can opener is a handheld metal tool that cuts the lids off of canned food, which you can buy at the grocery store. You use it by turning a knob, which puts pressure on two blades, which cut through the metal lid of the can. + +Thank you. diff --git a/eleventy.config.drafts.js b/eleventy.config.drafts.js deleted file mode 100644 index ecc2540..0000000 --- a/eleventy.config.drafts.js +++ /dev/null @@ -1,52 +0,0 @@ -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; - } -}; - -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; - } -}; - -const _eleventyComputedPermalink = eleventyComputedPermalink; -export { _eleventyComputedPermalink as eleventyComputedPermalink }; -const _eleventyComputedExcludeFromCollections = eleventyComputedExcludeFromCollections; -export { _eleventyComputedExcludeFromCollections as eleventyComputedExcludeFromCollections }; - -export default 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; - }); -} diff --git a/eleventy.config.js b/eleventy.config.js index 9689ee3..99da04c 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -3,15 +3,22 @@ import pluginSyntaxHighlight from "@11ty/eleventy-plugin-syntaxhighlight"; import { EleventyHtmlBasePlugin } from "@11ty/eleventy"; import pluginRss from '@11ty/eleventy-plugin-rss'; -import pluginDrafts from "./eleventy.config.drafts.js"; - /** @param {import('@11ty/eleventy').UserConfig} eleventyConfig */ export default function(eleventyConfig) { + console.log(process.env); + if (process.env.NODE_ENV === 'localhost') { console.log('metadata override'); eleventyConfig.addGlobalData('metadata.url', 'http://localhost:8080'); } + // Drafts + eleventyConfig.addPreprocessor('drafts', '*', (data) => { + if (data.draft && process.env.ELEVENTY_RUN_MODE === 'build') { + return false; + } + }); + eleventyConfig.addPassthroughCopy("content/**/*.png"); eleventyConfig.addPassthroughCopy("content/**/*.webp"); eleventyConfig.addPassthroughCopy('content/**/*.css'); @@ -24,9 +31,6 @@ export default function(eleventyConfig) { // Watch content images for the image pipeline. eleventyConfig.addWatchTarget("content/**/*.{svg,webp,png,jpeg}"); - // App plugins - eleventyConfig.addPlugin(pluginDrafts); - // Official plugins eleventyConfig.addBundle('css'); eleventyConfig.addPlugin(pluginSyntaxHighlight, {