nonscollectif-org/.eleventy.js

73 lines
2.1 KiB
JavaScript
Raw Normal View History

require('dotenv').config()
const { DateTime } = require("luxon");
const pluginNavigation = require("@11ty/eleventy-navigation");
2022-07-26 10:26:15 +00:00
const markdownIt = require('markdown-it')
const markdownItAttrs = require('markdown-it-attrs')
const markdownItOptions = {
html: true,
2022-08-24 19:42:05 +00:00
breaks: false,
2022-07-26 10:26:15 +00:00
linkify: true
}
module.exports = function(eleventyConfig) {
eleventyConfig.addPlugin(pluginNavigation);
2022-07-25 22:10:45 +00:00
eleventyConfig.setUseGitIgnore(false);
2022-08-09 19:51:50 +00:00
eleventyConfig.addPassthroughCopy("src/*.png");
eleventyConfig.addPassthroughCopy("src/*.ico");
2022-07-24 20:09:01 +00:00
eleventyConfig.addPassthroughCopy("src/css");
eleventyConfig.addPassthroughCopy("src/dl");
2022-08-10 08:19:13 +00:00
eleventyConfig.addPassthroughCopy("src/ressources/*.pdf");
2022-07-24 20:09:01 +00:00
eleventyConfig.addPassthroughCopy("src/images");
2022-08-05 14:54:24 +00:00
eleventyConfig.addPassthroughCopy("src/presse/images");
eleventyConfig.addPassthroughCopy("src/idees-recues/images");
eleventyConfig.addPassthroughCopy("src/actualites/images");
2022-06-26 23:58:49 +00:00
2022-08-24 19:42:05 +00:00
eleventyConfig.addFilter("toHTML", str => {
return new markdownIt(markdownItOptions).renderInline(str);
});
eleventyConfig.addFilter("readableDate", dateObj => {
return DateTime.fromJSDate(dateObj, {zone: 'utc'}).setLocale("fr").toFormat("dd LLL yyyy");
});
// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string
eleventyConfig.addFilter('htmlDateString', (dateObj) => {
return DateTime.fromJSDate(dateObj, {zone: 'utc'}).toFormat('yyyy-LL-dd');
});
// 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>'))
2022-06-28 12:45:08 +00:00
2022-07-26 10:26:15 +00:00
eleventyConfig.setLibrary('md', markdownIt(markdownItOptions).use(markdownItAttrs))
eleventyConfig.setFrontMatterParsingOptions({ excerpt: true });
2022-06-28 12:45:08 +00:00
return {
2022-07-24 20:09:01 +00:00
dir: {
input: 'src'
},
2022-06-28 12:45:08 +00:00
// Pre-process *.md files with: (default: `liquid`)
2022-07-26 10:26:15 +00:00
// markdownTemplateEngine: "njk",
2022-06-28 12:45:08 +00:00
// Pre-process *.html files with: (default: `liquid`)
htmlTemplateEngine: "njk",
}
}