sp-codes.de/.eleventy.js

93 lines
3 KiB
JavaScript
Raw Normal View History

2023-01-12 21:33:15 +00:00
const pluginRev = require("eleventy-plugin-rev");
const pluginSass = require("eleventy-sass");
const pluginTinyHtml = require("@sardine/eleventy-plugin-tinyhtml");
const pluginNavigation = require("@11ty/eleventy-navigation");
2020-06-01 19:44:08 +00:00
module.exports = function (eleventyConfig) {
2023-01-12 21:33:15 +00:00
eleventyConfig.addPlugin(pluginRev);
eleventyConfig.addPlugin(pluginTinyHtml);
eleventyConfig.addPlugin(pluginSass, {
2023-01-12 21:33:15 +00:00
sass: {
loadPaths: ["node_modules"],
style: "compressed",
sourceMap: false,
},
compileOptions: {
permalink: function (contents, inputPath) {
return (data) => {
return data.page.filePathStem.replace(/^\/scss\//, "/css/") + ".css";
};
}
},
rev: true
});
eleventyConfig.addPlugin(pluginNavigation);
2023-01-12 21:33:15 +00:00
2020-06-01 19:44:08 +00:00
eleventyConfig.setUseGitIgnore(false);
eleventyConfig.addPassthroughCopy({
2020-07-27 15:41:08 +00:00
"src/img": "img",
2021-06-14 15:41:33 +00:00
"src/font": "font",
"src/favicon.*": "",
2020-06-01 19:44:08 +00:00
});
eleventyConfig.addShortcode("translatedUrl", function (currentLocale, newLocale) {
return this.page.url.replace(new RegExp(`\/${currentLocale}\/`), `/${newLocale}/`);
});
2020-06-01 19:44:08 +00:00
eleventyConfig.addFilter('year', function (value) {
return value * 12;
});
eleventyConfig.addFilter("sum", function (value) {
2023-01-12 21:33:15 +00:00
return value.map(d => d.amount).reduce((a, b) => a + b, 0);
});
2021-06-12 23:09:52 +00:00
eleventyConfig.addFilter("amount", function (value) {
// TODO update language dynamically
return value.toLocaleString('de', {minimumFractionDigits: 2});
});
eleventyConfig.addFilter("banktransfers", function (donations) {
return donations
.flatMap(y => y.donations)
.filter(d => d.via === 'banktransfer')
.filter(d => d.first)
.length;
});
eleventyConfig.addFilter("cash", function (donations) {
return donations
.flatMap(y => y.donations)
.filter(d => d.via === 'cash')
.filter(d => d.first)
.length;
});
2024-04-01 11:47:10 +00:00
eleventyConfig.addCollection("series", function (collectionApi) {
return collectionApi.getAll()
.filter(p => p.data?.series)
.sort((p0, p1) => p0.data.order - p1.data.order)
.reduce((series, post) => {
series[post.data.series] = series[post.data.series] ?? [];
series[post.data.series].push(post);
return series;
}, {});
});
2020-06-01 19:44:08 +00:00
return {
2021-10-24 19:43:59 +00:00
// Pre-process *.md files with: (default: `liquid`)
markdownTemplateEngine: "njk",
// Pre-process *.html files with: (default: `liquid`)
htmlTemplateEngine: "njk",
// Opt-out of pre-processing global data JSON files: (default: `liquid`)
dataTemplateEngine: false,
2020-06-01 19:44:08 +00:00
dir: {
2020-07-27 15:41:08 +00:00
input: "src",
2020-06-01 19:44:08 +00:00
includes: "_includes",
layouts: "_includes/layouts",
2021-10-24 19:43:59 +00:00
data: "_data",
2020-06-01 19:44:08 +00:00
output: "dist"
}
};
};