diff --git a/README.md b/README.md index 613e848..e8a5fae 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ A starter repository showing how to build a blog with the [Eleventy](https://www - Automated [image optimization](https://www.11ty.dev/docs/plugins/image/) via the `{% image %}` shortcode (images can be co-located with posts) (with zero-JavaScript output). - Built-in [syntax highlighter](https://www.11ty.dev/docs/plugins/syntaxhighlight/) (with zero-JavaScript output). - Automated next/previous links on blog posts. +- Use `draft: true` to only show draft blog posts (during `--serve` and `--watch` run modes). Drafts are excluded from full builds. - Easily [deploy to a subfolder without changing any content](https://www.11ty.dev/docs/plugins/html-base/) - Easily configure templates via the [Eleventy Data Cascade](https://www.11ty.dev/docs/data-cascade/) - Output URLs are independent of content’s location on the file system. diff --git a/eleventy.config.js b/eleventy.config.js index 5399ef0..e0fef82 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -9,21 +9,6 @@ const eleventyImage = require("@11ty/eleventy-img"); const { EleventyHtmlBasePlugin } = require("@11ty/eleventy"); module.exports = function(eleventyConfig) { - eleventyConfig.addPlugin(function enableDrafts(eleventyConfig) { - let logged = false; - eleventyConfig.on("eleventy.before", ({runMode}) => { - // only show drafts in serve/watch modes - if(runMode === "serve" || runMode === "watch") { - process.env.BUILD_DRAFTS = true; - if(!logged) { - console.log( "[11ty/eleventy-base-blog] including `draft: true` posts" ); - } - - logged = true; - } - }); - }) - // Copy the contents of the `public` folder to the output folder // For example, `./public/css/` ends up in `_site/css/` eleventyConfig.addPassthroughCopy({ @@ -72,6 +57,26 @@ module.exports = function(eleventyConfig) { }); }); + // Drafts implementation, see `content/blog/blog.11tydata.js` for additional code. + // This section *could* be simplified to an environment variable in an npm script, + // but this way an ENV is not required and this code works cross-platform. + eleventyConfig.addPlugin(function enableDrafts(eleventyConfig) { + let logged = false; + eleventyConfig.on("eleventy.before", ({runMode}) => { + // Only show drafts in serve/watch modes + if(runMode === "serve" || runMode === "watch") { + process.env.BUILD_DRAFTS = true; + + // Only log once + if(!logged) { + console.log( "[11ty/eleventy-base-blog] including `draft: true` posts" ); + } + + logged = true; + } + }); + }) + // Filters eleventyConfig.addFilter("readableDate", (dateObj, format = "dd LLLL yyyy") => { return DateTime.fromJSDate(dateObj, {zone: 'utc'}).toFormat(format);