87 lines
2.5 KiB
JavaScript
87 lines
2.5 KiB
JavaScript
require('dotenv').config()
|
|
|
|
const { DateTime } = require("luxon");
|
|
|
|
const pluginNavigation = require("@11ty/eleventy-navigation");
|
|
const markdownIt = require('markdown-it')
|
|
const markdownItAttrs = require('markdown-it-attrs')
|
|
|
|
const markdownItOptions = {
|
|
html: true,
|
|
breaks: false,
|
|
linkify: true
|
|
}
|
|
|
|
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/dl");
|
|
eleventyConfig.addPassthroughCopy("src/ressources/*.pdf");
|
|
eleventyConfig.addPassthroughCopy("src/images");
|
|
eleventyConfig.addPassthroughCopy("src/presse/images");
|
|
eleventyConfig.addPassthroughCopy("src/idees-recues/images");
|
|
eleventyConfig.addPassthroughCopy("src/actualites/images");
|
|
|
|
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>'))
|
|
|
|
eleventyConfig.addCollection('actusHome', collection => {
|
|
return [
|
|
...collection
|
|
.getFilteredByTag('actualites')
|
|
.filter(post => {
|
|
console.log(post.data.tags);
|
|
return !post.data.tags.some(tag => tag === 'excludeFromHome')
|
|
}
|
|
)
|
|
.reverse()
|
|
.slice(0,3)
|
|
]
|
|
})
|
|
|
|
eleventyConfig.setLibrary('md', markdownIt(markdownItOptions).use(markdownItAttrs))
|
|
|
|
eleventyConfig.setFrontMatterParsingOptions({ excerpt: true });
|
|
|
|
return {
|
|
dir: {
|
|
input: 'src'
|
|
},
|
|
|
|
// Pre-process *.md files with: (default: `liquid`)
|
|
// markdownTemplateEngine: "njk",
|
|
|
|
// Pre-process *.html files with: (default: `liquid`)
|
|
htmlTemplateEngine: "njk",
|
|
}
|
|
}
|