text: const { DateTime } = require("luxon");
  const CleanCSS = require("clean-css");
  const UglifyJS = require("uglify-es");
  const htmlmin = require("html-minifier");
  const pluginRss = require("@11ty/eleventy-plugin-rss");
  const pluginPWA = require("eleventy-plugin-pwa");
  
  module.exports = function(eleventyConfig) {
    eleventyConfig.addLayoutAlias("post", "layouts/post.njk");
  
    // 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");
    });
  
    // 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;
    });
  
    //  PWA
    eleventyConfig.addPlugin(pluginPWA);
  
  
    // only content in the `posts/` directory
    eleventyConfig.addCollection("posts", function(collection) {
      return collection.getAllSorted().filter(function(item) {
        return item.inputPath.match(/^\.\/posts\//) !== null;
      });
    });
  
    
    // Don't process folders with static assets e.g. images
    eleventyConfig.addPassthroughCopy("favicon.ico");
    eleventyConfig.addPassthroughCopy("static/fonts");
    eleventyConfig.addPassthroughCopy("static/images/favicons");
    eleventyConfig.addPassthroughCopy("_includes/assets/css/inline.css");
    eleventyConfig.addPassthroughCopy("_includes/assets/css/main.css");
    eleventyConfig.addPassthroughCopy("_includes/assets/js/inline.js");
    eleventyConfig.addPassthroughCopy("manifest.json");
    eleventyConfig.addPassthroughCopy("service-worker.js");
    eleventyConfig.addPassthroughCopy("feed.xml");
    eleventyConfig.addPassthroughCopy("netlify.toml");
    eleventyConfig.addPassthroughCopy("admin");
  
    // RSS
    
    eleventyConfig.addPlugin(pluginRss);
  
    /* Markdown Plugins */
    let markdownIt = require("markdown-it");
    let markdownItOptions = {
      html: true
    };
    let mila = require("markdown-it-link-attributes");
    let milaOptions = {
      attrs: {
        target: "_blank",
        rel: "noopener noreferrer"
      }
    };
    let markdownLib = markdownIt(markdownItOptions).use(mila, milaOptions);
    eleventyConfig.setLibrary("md", markdownLib);
  
    return {
      templateFormats: ["md", "njk", "html", "liquid"],
      pathPrefix: "/",
  
      markdownTemplateEngine: "liquid",
      htmlTemplateEngine: "njk",
      dataTemplateEngine: "njk",
      passthroughFileCopy: true,
      dir: {
        input: ".",
        includes: "_includes",
        data: "_data",
        output: "_site"
      }
    };
  
  };
  