138 lines
4.5 KiB
JavaScript
138 lines
4.5 KiB
JavaScript
require('dotenv').config()
|
|
const pluginNavigation = require("@11ty/eleventy-navigation");
|
|
const fg = require('fast-glob');
|
|
const { DateTime } = require("luxon");
|
|
const markdownIt = require('markdown-it')
|
|
const markdownItAttrs = require('markdown-it-attrs')
|
|
const filters = require('./src/filters')
|
|
const galleryShortcode = require('./src/shortcodes/gallery')
|
|
|
|
const photosRectorat20221017 = fg.sync(['**/src/images/rectorat-2022-10-17/*', '!**/_site'])
|
|
const photosRectorat20221115 = fg.sync(['**/src/images/rectorat-2022-11-15/*', '!**/_site'])
|
|
|
|
const markdownItOptions = {
|
|
html: true,
|
|
breaks: false,
|
|
linkify: true
|
|
}
|
|
|
|
const parseDate = (date) => typeof date === 'string' ?
|
|
DateTime.fromISO(date) :
|
|
DateTime.fromJSDate(date, {zone: 'utc'})
|
|
|
|
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/comptes-rendus/*.pdf");
|
|
eleventyConfig.addPassthroughCopy("src/familles/jalil-karene/*.pdf");
|
|
eleventyConfig.addPassthroughCopy("src/images");
|
|
eleventyConfig.addPassthroughCopy("src/jipli");
|
|
eleventyConfig.addPassthroughCopy("src/presse/images");
|
|
eleventyConfig.addPassthroughCopy("src/presse/audios");
|
|
eleventyConfig.addPassthroughCopy("src/idees-recues/images");
|
|
eleventyConfig.addPassthroughCopy("src/actualites/images");
|
|
eleventyConfig.addPassthroughCopy({
|
|
"node_modules/photoswipe/dist/photoswipe.css": "js/photoswipe.css",
|
|
"node_modules/photoswipe/dist/photoswipe.esm.js": "js/photoswipe.esm.js",
|
|
"node_modules/photoswipe/dist/photoswipe-lightbox.esm.js": "js/photoswipe-lightbox.esm.js"
|
|
})
|
|
|
|
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');
|
|
});
|
|
|
|
// 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>'))
|
|
|
|
filters(eleventyConfig);
|
|
|
|
eleventyConfig.addCollection('actusHome', collection => {
|
|
return [
|
|
...collection
|
|
.getFilteredByTag('actualites')
|
|
.filter(post => !post.data.tags.some(tag => tag === 'excludeFromHome'))
|
|
.reverse()
|
|
.slice(0,3)
|
|
]
|
|
})
|
|
|
|
eleventyConfig.addCollection('photosRectorat20221017', function() {
|
|
return photosRectorat20221017;
|
|
});
|
|
|
|
eleventyConfig.addCollection('photosRectorat20221115', function() {
|
|
return photosRectorat20221115;
|
|
});
|
|
|
|
eleventyConfig.addCollection('presseNonscollectif', collection => [
|
|
...collection
|
|
.getFilteredByTags('presse', 'nonscollectif')
|
|
.reverse()
|
|
])
|
|
|
|
eleventyConfig.addCollection('presseHome', collection => [
|
|
...collection
|
|
.getFilteredByTags('presse', 'nonscollectif')
|
|
.filter(post => !post.data.tags.some(tag => tag === 'excludeFromHome'))
|
|
.reverse()
|
|
.slice(0,3)
|
|
])
|
|
|
|
eleventyConfig.addCollection('presseManif1', collection => [
|
|
...collection
|
|
.getFilteredByTags('presse', 'nonscollectif')
|
|
.filter(post => post.date >= DateTime.fromISO('2022-09-01') && post.date < DateTime.fromISO('2022-09-15'))
|
|
])
|
|
|
|
eleventyConfig.addCollection('presseManif15', collection => [
|
|
...collection
|
|
.getFilteredByTags('presse', 'nonscollectif')
|
|
.filter(post => post.date >= DateTime.fromISO('2022-09-15') && post.date < DateTime.fromISO('2022-09-17'))
|
|
])
|
|
|
|
eleventyConfig.addAsyncShortcode('gallery', galleryShortcode);
|
|
|
|
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",
|
|
}
|
|
}
|