2022-09-29 23:21:14 +00:00
|
|
|
require('dotenv').config()
|
|
|
|
|
|
|
|
const { DateTime } = require("luxon");
|
|
|
|
const pluginNavigation = require("@11ty/eleventy-navigation");
|
|
|
|
const markdownIt = require('markdown-it')
|
|
|
|
const markdownItAttrs = require('markdown-it-attrs')
|
2022-11-27 22:00:04 +00:00
|
|
|
const Image = require("@11ty/eleventy-img");
|
2022-09-29 23:21:14 +00:00
|
|
|
|
|
|
|
const markdownItOptions = {
|
|
|
|
html: true,
|
|
|
|
breaks: false,
|
|
|
|
linkify: true
|
|
|
|
}
|
|
|
|
|
|
|
|
const parseDate = (date) => typeof date === 'string' ?
|
2023-12-26 12:41:26 +00:00
|
|
|
DateTime.fromISO(date).setZone("Europe/Paris") :
|
|
|
|
DateTime.fromJSDate(date, {zone: 'utc'}).setZone("Europe/Paris")
|
2022-09-29 23:21:14 +00:00
|
|
|
|
2023-12-26 14:51:18 +00:00
|
|
|
async function imageShortcode(src, alt, sizes, classes) {
|
2022-11-27 22:00:04 +00:00
|
|
|
let metadata = await Image(src, {
|
|
|
|
widths: [300, 600, 1200],
|
|
|
|
formats: ["webp", "jpg"],
|
|
|
|
outputDir: '_site/images/generated',
|
|
|
|
urlPath: '/images/generated'
|
|
|
|
});
|
|
|
|
|
|
|
|
let imageAttributes = {
|
|
|
|
alt,
|
|
|
|
sizes,
|
|
|
|
loading: "lazy",
|
|
|
|
decoding: "async",
|
2023-12-26 14:51:18 +00:00
|
|
|
class: classes
|
2022-11-27 22:00:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// You bet we throw an error on missing alt in `imageAttributes` (alt="" works okay)
|
|
|
|
return Image.generateHTML(metadata, imageAttributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-29 23:21:14 +00:00
|
|
|
module.exports = function(eleventyConfig) {
|
|
|
|
eleventyConfig.addPlugin(pluginNavigation);
|
|
|
|
|
|
|
|
eleventyConfig.setUseGitIgnore(false);
|
|
|
|
|
|
|
|
eleventyConfig.addPassthroughCopy("src/*.png");
|
|
|
|
eleventyConfig.addPassthroughCopy("src/*.ico");
|
|
|
|
eleventyConfig.addPassthroughCopy("src/css");
|
|
|
|
eleventyConfig.addPassthroughCopy("src/js");
|
|
|
|
eleventyConfig.addPassthroughCopy("src/fonts");
|
|
|
|
eleventyConfig.addPassthroughCopy("src/images");
|
2022-12-09 16:15:12 +00:00
|
|
|
eleventyConfig.addPassthroughCopy("src/il/*.jpg");
|
|
|
|
eleventyConfig.addPassthroughCopy("src/il/*.pdf");
|
2023-12-24 23:53:54 +00:00
|
|
|
eleventyConfig.addPassthroughCopy("src/araberlin/*.webp");
|
|
|
|
eleventyConfig.addPassthroughCopy("src/araberlin/*.pdf");
|
2022-09-29 23:21:14 +00:00
|
|
|
|
|
|
|
eleventyConfig.addFilter("toHTML", str => {
|
|
|
|
return new markdownIt(markdownItOptions).renderInline(str);
|
|
|
|
});
|
|
|
|
|
|
|
|
eleventyConfig.addFilter("readableDate", dateObj => {
|
|
|
|
return parseDate(dateObj).setLocale("fr").toFormat("dd LLL yyyy");
|
|
|
|
});
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string
|
|
|
|
eleventyConfig.addFilter('htmlDateString', (dateObj) => {
|
|
|
|
return parseDate(dateObj).toFormat('yyyy-LL-dd');
|
|
|
|
});
|
2023-12-26 12:41:26 +00:00
|
|
|
eleventyConfig.addFilter('htmlDateTimeISO', (dateObj) => {
|
|
|
|
return parseDate(dateObj).toISO();
|
|
|
|
});
|
2022-09-29 23:21:14 +00:00
|
|
|
|
|
|
|
// Get the first `n` elements of a collection.
|
|
|
|
eleventyConfig.addFilter("head", (array, n) => {
|
|
|
|
if (!Array.isArray(array) || array.length === 0) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
if (n < 0) {
|
|
|
|
return array.slice(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
return array.slice(0, n);
|
|
|
|
});
|
|
|
|
|
|
|
|
eleventyConfig.addFilter("nlToBr", string => string.replaceAll('\n', '<br>'))
|
|
|
|
|
|
|
|
eleventyConfig.setLibrary('md', markdownIt(markdownItOptions).use(markdownItAttrs))
|
|
|
|
|
|
|
|
eleventyConfig.setFrontMatterParsingOptions({ excerpt: true });
|
|
|
|
|
2022-11-27 22:00:04 +00:00
|
|
|
eleventyConfig.addAsyncShortcode("image", imageShortcode)
|
|
|
|
|
2022-09-29 23:21:14 +00:00
|
|
|
return {
|
|
|
|
dir: {
|
|
|
|
input: 'src'
|
|
|
|
},
|
|
|
|
|
|
|
|
// Pre-process *.md files with: (default: `liquid`)
|
|
|
|
// markdownTemplateEngine: "njk",
|
|
|
|
|
|
|
|
// Pre-process *.html files with: (default: `liquid`)
|
|
|
|
htmlTemplateEngine: "njk",
|
|
|
|
}
|
|
|
|
}
|