-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy path.eleventy.js
59 lines (52 loc) · 1.87 KB
/
.eleventy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const pluginRss = require("@11ty/eleventy-plugin-rss");
const dateOptions = {
dateStyle: 'short',
timeZone: 'Europe/Paris',
};
const dateFormat = (date) => new Intl.DateTimeFormat('fr-FR', dateOptions).format(date);
const getLatestDate = (page) => {
return Math.max(page.date.getTime(), page.data.update?.getTime() ?? 0)
}
module.exports = function(eleventyConfig) {
eleventyConfig.addPassthroughCopy("site/assets");
eleventyConfig.addPassthroughCopy("site/favicon.ico");
eleventyConfig.addNunjucksFilter("getLatestDate", function(page) {
return new Date(getLatestDate(page));
});
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addCollection("dateSortedLinks", function(collectionApi) {
// get unsorted items
const all = collectionApi.getAll().sort((a, b) => {
const aDate = getLatestDate(a);
const bDate = getLatestDate(b);
return bDate - aDate;
});
return all;
});
eleventyConfig.addShortcode(
"liste",
(collection) => {
return `<section class="liste">
${collection.map(item => {
return `
<article style="--hue: ${ item.data.couleur ?? '0' }deg;" ${!!item.data.lang ? `lang="${item.data.lang}"` : ''}>
<h3>
${ item.data.titre } ${ item.data.lang == 'en' ? '<small>(in English)</small>' : ''}
</h3>
<p>
<span class="adresse">${ item.data.adresse.replace(/^https?:\/\//, '') }</span>
<small>
Ajouté le ${ dateFormat(item.date) }${ !!item.data.update
? `, mis à jour le ${ dateFormat(item.data.update) }`
: ""
}
</small>
</p>
<span aria-hidden class="emoji">${ item.data.emoji }</span>
<a href="${ item.data.adresse }" rel="nofollow" ${!!item.data.lang ? `hreflang="${item.data.lang}"` : ''}>
<span class="sr-only">Visiter ${ item.data.adresse.replace(/^https?:\/\//, '') }</span>
</a>
</article>`}).join('')}
</section>
`;});
};