2024-09-14 10:59:22 +02:00
|
|
|
const { EleventyHtmlBasePlugin, EleventyI18nPlugin } = require("@11ty/eleventy");
|
2024-09-13 17:18:41 +02:00
|
|
|
const eleventyNavigationPlugin = require("@11ty/eleventy-navigation");
|
2024-10-02 18:18:54 +02:00
|
|
|
const faviconsPlugin = require("eleventy-plugin-gen-favicons");
|
2024-09-15 13:18:05 +02:00
|
|
|
const bundlerPlugin = require("@11ty/eleventy-plugin-bundle");
|
2024-09-24 17:54:42 +02:00
|
|
|
const pluginIcons = require('eleventy-plugin-icons');
|
2024-10-01 14:42:16 +02:00
|
|
|
const Image = require("@11ty/eleventy-img");
|
2024-09-26 15:39:47 +02:00
|
|
|
const yaml = require("js-yaml");
|
2024-09-14 12:44:27 +02:00
|
|
|
const fs = require('fs');
|
2024-09-12 13:41:52 +02:00
|
|
|
|
|
|
|
module.exports = function(eleventyConfig) {
|
|
|
|
eleventyConfig.addPlugin(EleventyHtmlBasePlugin);
|
2024-09-13 17:18:41 +02:00
|
|
|
eleventyConfig.addPlugin(eleventyNavigationPlugin);
|
2024-09-14 10:59:22 +02:00
|
|
|
eleventyConfig.addPlugin(EleventyI18nPlugin, {
|
|
|
|
defaultLanguage: "de",
|
|
|
|
});
|
2024-09-15 13:18:05 +02:00
|
|
|
eleventyConfig.addPlugin(bundlerPlugin);
|
2024-09-24 17:54:42 +02:00
|
|
|
let fontawesomePath = "node_modules/@fortawesome/fontawesome-free/svgs";
|
|
|
|
eleventyConfig.addPlugin(pluginIcons, {
|
|
|
|
sources: [
|
|
|
|
{ name: "regular", path: `${fontawesomePath}/regular`, default: true },
|
|
|
|
{ name: "solid", path: `${fontawesomePath}/solid` },
|
|
|
|
{ name: "brands", path: `${fontawesomePath}/brands` },
|
|
|
|
],
|
2024-09-27 15:35:51 +02:00
|
|
|
icon: {
|
|
|
|
shortcode: "rawIcon",
|
|
|
|
},
|
|
|
|
});
|
2024-10-02 18:18:54 +02:00
|
|
|
eleventyConfig.addPlugin(faviconsPlugin, {});
|
2024-09-27 15:35:51 +02:00
|
|
|
|
|
|
|
// override icon shortcode to make the SVGs accessible
|
|
|
|
eleventyConfig.addAsyncShortcode("icon", async function(input, attrs) {
|
2024-09-28 12:35:37 +02:00
|
|
|
let out;
|
2024-09-27 15:35:51 +02:00
|
|
|
if (!attrs || !("title" in attrs)) {
|
2024-09-28 12:35:37 +02:00
|
|
|
out = await eleventyConfig.nunjucksAsyncShortcodes.rawIcon(input, attrs);
|
|
|
|
} else {
|
|
|
|
const { title, ...newAttrs } = attrs;
|
|
|
|
newAttrs.role = "img";
|
|
|
|
const svgStr = await eleventyConfig.nunjucksAsyncShortcodes.rawIcon(input, newAttrs);
|
|
|
|
const match = svgStr.match(/(<svg.*?>)(.*$)/s);
|
|
|
|
out = match[1] + "<title>" + title + "</title>" + match[2];
|
2024-09-27 15:35:51 +02:00
|
|
|
}
|
2024-09-28 12:35:37 +02:00
|
|
|
// line breaks cause some issues
|
|
|
|
return out.replaceAll("\n", "");
|
2024-09-24 17:54:42 +02:00
|
|
|
});
|
2024-09-12 13:41:52 +02:00
|
|
|
|
2024-10-01 14:42:16 +02:00
|
|
|
// responsive images
|
|
|
|
eleventyConfig.addShortcode("image", async function(src, alt, sizes) {
|
|
|
|
let metadata = await Image(src, {
|
|
|
|
outputDir: "./_site/img/",
|
|
|
|
widths: [480, 1024, 1920, 2560, "auto"],
|
|
|
|
});
|
|
|
|
let imageAttributes = {
|
|
|
|
alt,
|
|
|
|
sizes,
|
|
|
|
loading: "lazy",
|
|
|
|
decoding: "async",
|
|
|
|
};
|
|
|
|
return Image.generateHTML(metadata, imageAttributes);
|
|
|
|
});
|
|
|
|
|
2024-09-26 17:47:50 +02:00
|
|
|
// process the logo files
|
|
|
|
eleventyConfig.addTemplateFormats("logo.svg");
|
|
|
|
eleventyConfig.addExtension("logo.svg", {
|
|
|
|
outputFileExtension: "svg",
|
|
|
|
|
|
|
|
compile: async (inputContent) => {
|
|
|
|
return async (data) => {
|
|
|
|
// insert year
|
2024-09-26 18:23:45 +02:00
|
|
|
let svg = inputContent.replace("{{ese.year}}", String(data.ese.year).slice(-2));
|
2024-09-26 17:47:50 +02:00
|
|
|
// insert color
|
2024-09-26 18:23:45 +02:00
|
|
|
svg = svg.replaceAll("{{ese.color}}", data.ese.color);
|
2024-09-26 17:47:50 +02:00
|
|
|
|
|
|
|
// render text to path
|
|
|
|
// TODO replace with ESM import once we switch to Eleventy v3
|
|
|
|
const Session = (await import('svg-text-to-path')).default;
|
|
|
|
let session = new Session(svg, {
|
|
|
|
fonts: {
|
|
|
|
"Aileron Thin": [{
|
|
|
|
wght: 400,
|
|
|
|
source: "./submodules/aileron/fonts/Aileron-Thin.ttf",
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
await session.replaceAll();
|
|
|
|
|
2024-10-02 18:18:54 +02:00
|
|
|
let finalSvg = session.getSvgString();
|
|
|
|
|
|
|
|
// no idea why this gets mangled
|
|
|
|
finalSvg = finalSvg.replaceAll("svg:svg", "svg");
|
|
|
|
finalSvg = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n' + finalSvg;
|
|
|
|
|
|
|
|
return finalSvg;
|
2024-09-26 17:47:50 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-09-26 15:39:47 +02:00
|
|
|
eleventyConfig.addDataExtension("yaml, yml", yaml.load);
|
|
|
|
|
2024-09-14 10:59:22 +02:00
|
|
|
eleventyConfig.addFilter("pageLang", function(value) {
|
|
|
|
return value.filter(item => item.page.lang === this.page.lang)
|
|
|
|
});
|
|
|
|
|
2024-10-04 13:54:40 +02:00
|
|
|
// translations
|
|
|
|
eleventyConfig.addFilter("localized", function(item) {
|
|
|
|
if (typeof item === "string") return item;
|
|
|
|
return item[this.ctx.lang];
|
|
|
|
});
|
|
|
|
|
2024-10-02 15:19:22 +02:00
|
|
|
const md_link_open = function (tokens, idx, options, env, self) {
|
|
|
|
const href = tokens[idx].attrGet('href');
|
|
|
|
|
|
|
|
if (href.startsWith('http')) {
|
|
|
|
tokens[idx].attrSet('target', '_blank');
|
|
|
|
tokens[idx].attrSet('rel', 'noreferrer');
|
|
|
|
}
|
2024-10-04 20:24:37 +02:00
|
|
|
// this would be useful but it's broken
|
|
|
|
// else {
|
|
|
|
// const newHref = eleventyConfig.javascriptFunctions.locale_url(href);
|
|
|
|
// tokens[idx].attrSet('href', newHref);
|
|
|
|
// }
|
2024-10-02 15:19:22 +02:00
|
|
|
|
|
|
|
return self.renderToken(tokens, idx, options);
|
|
|
|
};
|
|
|
|
|
2024-09-27 16:32:04 +02:00
|
|
|
eleventyConfig.addAsyncFilter('mdInline', async function(value) {
|
|
|
|
// TODO replace with ESM import once we switch to Eleventy v3
|
|
|
|
const md = (await import('markdown-it/index.mjs')).default();
|
|
|
|
|
|
|
|
// customize link rendering
|
2024-10-02 15:19:22 +02:00
|
|
|
md.renderer.rules.link_open = md_link_open;
|
2024-09-27 16:32:04 +02:00
|
|
|
|
|
|
|
return md.renderInline(value);
|
|
|
|
});
|
|
|
|
|
2024-10-02 15:19:22 +02:00
|
|
|
eleventyConfig.amendLibrary("md", mdLib => mdLib.renderer.rules.link_open = md_link_open);
|
|
|
|
|
2024-09-20 14:46:23 +02:00
|
|
|
// copy aileron font
|
2024-09-20 13:22:58 +02:00
|
|
|
eleventyConfig.addPassthroughCopy({'./submodules/aileron/fonts/*.(ttf|woff|woff2)': 'fonts'})
|
|
|
|
eleventyConfig.addPassthroughCopy({'./submodules/aileron/aileron.lite.min.css': 'aileron.lite.min.css'})
|
2024-09-20 18:39:35 +02:00
|
|
|
// copy static files
|
|
|
|
eleventyConfig.addPassthroughCopy('./static')
|
2024-09-15 17:23:25 +02:00
|
|
|
|
2024-09-14 12:44:27 +02:00
|
|
|
// copy german start page to root url
|
|
|
|
eleventyConfig.on(
|
|
|
|
"eleventy.after",
|
|
|
|
async ({ dir, runMode, outputMode }) => {
|
|
|
|
if (outputMode === "fs") {
|
|
|
|
fs.copyFile(`${dir.output}/de/index.html`, `${dir.output}/index.html`, (err) => {
|
2024-10-02 18:18:54 +02:00
|
|
|
if (err && err.code !== 'ENOENT') console.log(err);
|
2024-09-14 12:44:27 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2024-09-26 18:23:45 +02:00
|
|
|
const eseData = yaml.load(fs.readFileSync('./content/_data/ese.yaml'));
|
|
|
|
|
2024-09-12 13:41:52 +02:00
|
|
|
return {
|
|
|
|
dir: {
|
|
|
|
input: "content",
|
2024-09-13 17:04:16 +02:00
|
|
|
includes: "../_includes",
|
2024-09-12 13:41:52 +02:00
|
|
|
},
|
2024-09-26 18:23:45 +02:00
|
|
|
pathPrefix: `/${eseData.year}/`,
|
2024-10-02 15:19:22 +02:00
|
|
|
markdownTemplateEngine: "njk",
|
2024-09-12 13:41:52 +02:00
|
|
|
}
|
|
|
|
};
|