punkfairie-site/.eleventy.js

70 lines
1.8 KiB
JavaScript
Raw Permalink Normal View History

const esbuild = require("esbuild");
2023-06-05 18:33:36 -07:00
module.exports = function (eleventyConfig) {
2023-06-21 12:13:56 -07:00
// Process SCSS
eleventyConfig.addPlugin(require("eleventy-sass"), {
postcss: require("postcss")([
require("postcss-preset-env"),
require("cssnano"),
2023-06-21 12:13:56 -07:00
]),
});
2023-06-21 12:13:56 -07:00
// Add noopener to links
eleventyConfig.addPlugin(require("eleventy-plugin-automatic-noopener"), {
2023-06-21 12:13:56 -07:00
noreferrer: true,
});
2023-06-21 12:13:56 -07:00
// Copy CSS assets
eleventyConfig.addPassthroughCopy("src/style/assets");
2023-06-21 12:13:56 -07:00
// Copy collections & links
eleventyConfig.addPassthroughCopy("src/collections/images/**/*");
eleventyConfig.addPassthroughCopy("src/images");
// start page
eleventyConfig.addPassthroughCopy("src/start/index.html");
eleventyConfig.addPassthroughCopy("src/start/style.css");
eleventyConfig.addPassthroughCopy("src/favicon.png");
2023-06-21 12:13:56 -07:00
// Process JS
eleventyConfig.addTemplateFormats("js");
eleventyConfig.addExtension("js", {
outputFileExtension: "js",
2023-06-21 12:13:56 -07:00
compile: async (content, path) => {
if (path !== "./src/js/main.js") {
return;
2023-06-21 12:13:56 -07:00
}
return async () => {
const output = await esbuild.build({
target: "es2020",
2023-06-21 12:13:56 -07:00
entryPoints: [path],
minify: true,
bundle: true,
write: false,
});
2023-06-21 12:13:56 -07:00
return output.outputFiles[0].text;
};
2023-06-21 12:13:56 -07:00
},
});
2023-06-21 12:13:56 -07:00
// Convert img filename to alt text
eleventyConfig.addFilter("toAlt", (text) => {
const basename = text.split(".");
return basename[0].replace(/-/g, " ");
});
2023-06-21 12:13:56 -07:00
// Convert diary date path to slug
eleventyConfig.addFilter("datePathSlugify", (path) => {
const folders = path.split("/");
const file = folders.pop().split(".");
return `${folders[3]}/${folders[4]}/${file[0]}`;
});
2023-06-21 12:13:56 -07:00
// RSS
eleventyConfig.addPlugin(require("@11ty/eleventy-plugin-rss"));
2023-06-21 12:13:56 -07:00
return { dir: { input: "src", output: "dist" } };
};