const { DateTime } = require("luxon"); const CleanCSS = require("clean-css"); const UglifyJS = require("uglify-es"); const htmlmin = require("html-minifier"); const uslug = require("uslug"); const uslugify = (s) => uslug(s); const eleventyNavigationPlugin = require("@11ty/eleventy-navigation"); // TODO: Switch ToC to https://www.npmjs.com/package/markdown-it-toc-done-right const pluginTOC = require("eleventy-plugin-nesting-toc"); module.exports = function (eleventyConfig) { // Eleventy Navigation https://www.11ty.dev/docs/plugins/navigation/ eleventyConfig.addPlugin(eleventyNavigationPlugin); eleventyConfig.addPlugin(pluginTOC); module.exports = function (eleventyConfig) { let markdownIt = require("markdown-it"); let markdownItEmoji = require("markdown-it-emoji"); let options = { html: false, xhtmlOut: true, linkify: true, typographer: true, permalink: true, }; let anchor_options = { slugify: uslugify, permalink: true, renderPermalink, permalinkClass: "header-anchor", permalinkSpace: true, permalinkSymbol: "#", permalinkBefore: true, permalinkHref, permalinkAttrs, }; let markdownLib = markdownIt(options) .use(markdownItEmoji) .use(require("markdown-it-anchor"), anchor_options); eleventyConfig.setLibrary("md", markdownLib); }; // Configuration API: use eleventyConfig.addLayoutAlias(from, to) to add // layout aliases! Say you have a bunch of existing content using // layout: post. If you don’t want to rewrite all of those values, just map // post to a new file like this: // eleventyConfig.addLayoutAlias("post", "layouts/my_new_post_layout.njk"); // Merge data instead of overriding // https://www.11ty.dev/docs/data-deep-merge/ eleventyConfig.setDataDeepMerge(true); // Add support for maintenance-free post authors // Adds an authors collection using the author key in our post frontmatter // Thanks to @pdehaan: https://github.com/pdehaan eleventyConfig.addCollection("authors", (collection) => { const blogs = collection.getFilteredByGlob("posts/*.md"); return blogs.reduce((coll, post) => { const author = post.data.author; if (!author) { return coll; } if (!coll.hasOwnProperty(author)) { coll[author] = []; } coll[author].push(post.data); return coll; }, {}); }); // Add support for maintenance-free tag list eleventyConfig.addCollection("tagsList", (collectionApi) => { const tagsSet = new Set(); collectionApi.getAll().forEach((item) => { if (!item.data.tags) return; item.data.tags.forEach((tag) => tagsSet.add(tag)); }); return tagsSet; }); // Add support for Limiting the output of a Collection // Found at https://github.com/11ty/eleventy/issues/1368 eleventyConfig.addNunjucksFilter("limit", (arr, limit) => arr.slice(0, limit) ); // Consider moving to eleventy-plugin-date | https://www.npmjs.com/package/eleventy-plugin-date // Date formatting (human readable) eleventyConfig.addFilter("readableDate", (dateObj) => { return DateTime.fromJSDate(dateObj).toFormat("dd LLL yyyy"); }); // Date formatting (machine readable) eleventyConfig.addFilter("machineDate", (dateObj) => { return DateTime.fromJSDate(dateObj).toFormat("yyyy-MM-dd"); }); // Date formatting (MMYY) eleventyConfig.addFilter("mmyy", (dateObj) => { return DateTime.fromJSDate(dateObj).toFormat("LLL—yy"); }); // Minify CSS eleventyConfig.addFilter("cssmin", function (code) { return new CleanCSS({}).minify(code).styles; }); // Minify JS eleventyConfig.addFilter("jsmin", function (code) { let minified = UglifyJS.minify(code); if (minified.error) { console.log("UglifyJS error: ", minified.error); return code; } return minified.code; }); // Minify HTML output eleventyConfig.addTransform("htmlmin", function (content, outputPath) { if (outputPath.indexOf(".html") > -1) { let minified = htmlmin.minify(content, { useShortDoctype: true, removeComments: true, collapseWhitespace: true, }); return minified; } return content; }); // Don't process folders with static assets e.g. images eleventyConfig.addPassthroughCopy("favicon.ico"); eleventyConfig.addPassthroughCopy("*.png"); eleventyConfig.addPassthroughCopy("*.svg"); eleventyConfig.addPassthroughCopy("static/img"); eleventyConfig.addPassthroughCopy("admin"); eleventyConfig.addPassthroughCopy("_includes/assets/"); /* Markdown Plugins */ let markdownIt = require("markdown-it"); let markdownItAnchor = require("markdown-it-anchor"); let options = { html: true, breaks: true, linkify: true, }; let opts = { permalink: false, }; eleventyConfig.setLibrary( "md", markdownIt(options).use(markdownItAnchor, opts) ); return { templateFormats: ["md", "njk", "html", "liquid"], // If your site lives in a different subdirectory, change this. // Leading or trailing slashes are all normalized away, so don’t worry about it. // If you don’t have a subdirectory, use "" or "/" (they do the same thing) // This is only used for URLs (it does not affect your file structure) pathPrefix: "/", markdownTemplateEngine: "liquid", htmlTemplateEngine: "njk", dataTemplateEngine: "njk", dir: { input: ".", includes: "_includes", data: "_data", output: "_site", }, }; };