lucht/.eleventy.js

114 lines
2.9 KiB
JavaScript
Raw Normal View History

// const { DateTime } = require("luxon");
2021-09-03 02:05:52 +00:00
const pluginRss = require("@11ty/eleventy-plugin-rss");
const svgSprite = require("eleventy-plugin-svg-sprite");
const dateFilter = require("./src/filters/dateFilter.js");
const cleanCSS = require("clean-css");
2023-10-06 11:16:52 +00:00
//const eleventyWebcPlugin = require("@11ty/eleventy-plugin-webc");
//const { eleventyImagePlugin } = require("@11ty/eleventy-img");
const Image = require('@11ty/eleventy-img');
2021-09-03 02:05:52 +00:00
2021-08-31 02:16:17 +00:00
module.exports = function (config) {
config.setServerOptions({
// Whether the live reload snippet is used
liveReload: true,
port: 3456,
watch: ["dist/**/*.css"],
showAllHosts: true,
});
2021-09-05 19:30:48 +00:00
// PASSTHROUGHS
2023-10-06 11:16:52 +00:00
//config.addPassthroughCopy("src/assets/images/");
2021-09-02 01:20:51 +00:00
2021-09-05 19:30:48 +00:00
// LAYOUTS //
config.addLayoutAlias("base", "layouts/base.njk");
config.addLayoutAlias("post", "layouts/post.njk");
2021-09-03 02:05:52 +00:00
// FILTERS //
// date filter
config.addFilter("dateFilter", dateFilter);
// clean and inline CSS
config.addFilter("cssmin", function (code) {
return new cleanCSS({}).minify(code).styles;
});
2021-09-05 19:30:48 +00:00
// TRANSFORMS //
// minify HTML
2021-09-03 02:05:52 +00:00
const htmlMinTransform = require("./src/transforms/html-min.js");
const isProduction = process.env.ELEVENTY_ENV === "production";
// html min only in production
if (isProduction) {
config.addTransform("htmlmin", htmlMinTransform);
}
2021-09-05 19:30:48 +00:00
// PLUG-INS //
2021-09-03 02:05:52 +00:00
config.addPlugin(pluginRss);
config.addPlugin(svgSprite, {
path: "./src/assets/icons",
svgShortcode: "icon",
globalClasses: "icon",
});
2023-10-06 11:16:52 +00:00
// WebC
// config.addPlugin(eleventyWebcPlugin, {
// components: [
// // …
// // Add as a global WebC component
// "npm:@11ty/eleventy-img/*.webc",
// ]
// });
// Image plugin
// config.addPlugin(eleventyImagePlugin, {
// // Set global default options
// formats: ["webp", "jpeg"],
// urlPath: "/assets/images/",
// outputDir: "./dist/assets/images/",
// // Notably `outputDir` is resolved automatically
// // to the project output directory
// defaultAttributes: {
// loading: "lazy",
// decoding: "async"
// }
// });
// SHORTCODES
config.addShortcode("image", async function(src, cls, alt, sizes) {
let metadata = await Image(src, {
widths: [300, 600],
formats: ["webp", "jpeg"],
urlPath: "/assets/images/",
outputDir: "dist/assets/images/",
});
let imageAttributes = {
class: cls,
alt,
sizes,
loading: "lazy",
decoding: "async",
};
// You bet we throw an error on a missing alt (alt="" works okay)
return Image.generateHTML(metadata, imageAttributes);
});
2021-09-05 19:30:48 +00:00
// EXTRAS //
// Post List Excerpts
config.setFrontMatterParsingOptions({
excerpt: true,
excerpt_separator: "<!-- excerpt -->",
});
2021-09-03 02:05:52 +00:00
2021-09-05 19:30:48 +00:00
// BASE CONFIGURATION //
2021-08-31 02:16:17 +00:00
return {
dir: {
input: "src",
output: "dist",
includes: "includes",
data: "data",
},
2021-09-03 02:05:52 +00:00
templateFormats: ["html", "njk", "md", "11ty.js"],
2021-08-31 02:16:17 +00:00
htmlTemplateEngine: "njk",
markdownTemplateEngine: "njk",
};
};