This commit is contained in:
Zach Leatherman 2023-01-23 16:48:51 -06:00
parent cab874cb52
commit 5e3b9a16e9
2 changed files with 21 additions and 15 deletions

View File

@ -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 contents location on the file system.

View File

@ -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);