-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
180 lines (140 loc) · 5.83 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import {eleventyImageTransformPlugin} from "@11ty/eleventy-img"
import syntaxHighlight from "@11ty/eleventy-plugin-syntaxhighlight"
import {EleventyHtmlBasePlugin, EleventyI18nPlugin, IdAttributePlugin} from "@11ty/eleventy";
import {feedPlugin} from "@11ty/eleventy-plugin-rss";
import yaml from "js-yaml"
import markdownIt from "markdown-it";
export default function (eleventyConfig) {
let options = {
html: true,
breaks: true,
linkify: true,
};
eleventyConfig.setLibrary("md", markdownIt(options));
eleventyConfig.addFilter("toLocaleStringFr", function (date) {
return new Date(date).toLocaleString("fr-FR",
{weekday: "long", month: "long", day: "numeric", year: "numeric"})
});
eleventyConfig.addFilter("toLocaleTimeStringFr", function (date) {
return new Date(date).toLocaleTimeString("fr-FR",
{hour: "2-digit", minute: "2-digit", timeZone: "CET"})
});
eleventyConfig.addFilter("toLocaleStringFrShort", function (date) {
return new Date(date).toLocaleString("fr-FR",
{month: "2-digit", day: "numeric", year: "numeric"})
});
eleventyConfig.addFilter("toIsoString", function (date) {
return new Date(date).toISOString()
});
eleventyConfig.addCollection("blog", function (collectionApi) {
return collectionApi.getFilteredByGlob(["blog/*.md", "blog/*.html"]);
});
eleventyConfig.addCollection("latestFewFinishedArticles", function (collectionApi) {
return collectionApi.getFilteredByGlob(["blog/*.md", "blog/*.html"])
.filter(item => !item.data.stub)
.filter(item => !item.data.draft)
.sort((a, b) => b.date - a.date)
.slice(0, 5);
});
eleventyConfig.addCollection("allFinishedArticles", function (collectionApi) {
return collectionApi.getFilteredByGlob(["blog/*.md", "blog/*.html"])
.filter(item => !item.data.stub)
.filter(item => !item.data.draft)
.sort((a, b) => b.date - a.date);
});
eleventyConfig.addCollection("allNotesFromRecentToOlder", function (collectionApi) {
return collectionApi.getFilteredByGlob(["notes/*.md", "notes/*.html"])
.sort((a, b) => b.date - a.date)
});
eleventyConfig.addCollection("making-of", function (collectionApi) {
return collectionApi.getFilteredByGlob(["making-of/*.md", "making-of/*.html"]);
});
eleventyConfig.addCollection("glossaire", function (collectionApi) {
let filteredByGlob = collectionApi.getFilteredByGlob(["glossaire/*.md", "glossaire/*.html"]);
return filteredByGlob
.sort((a, b) => a.data.title.localeCompare(b.data.title));
});
eleventyConfig.addCollection("citations", function (collectionApi) {
let filteredByGlob = collectionApi.getFilteredByGlob(["citation/*.md", "citation/*.html"]);
return filteredByGlob
.sort((a, b) => a.data.title.localeCompare((b.data.title)))
.sort((a, b) => a.data.citation_auteur.localeCompare((b.data.citation_auteur)));
});
eleventyConfig.addCollection("kata-logue", function (collectionApi) {
return collectionApi.getFilteredByGlob(["kata-logue/*.md", "kata-logue/*.html"]);
});
eleventyConfig.addCollection("tags", function (collectionApi) {
return Array.from(new Set(collectionApi.getFilteredByGlob([
"kata-logue/*.md", "kata-logue/*.html",
"glossaire/*.md", "glossaire/*.html",
"notes/*.md", "notes/*.html",
"blog/*.md", "blog/*.html",
"making-of/*.md", "making-of/*.html",
])
.flatMap(page => page.data.tags)))
.filter(tag => tag !== undefined)
.sort((a, b) => a.localeCompare(b));
});
// Adds id to headings
eleventyConfig.addPlugin(IdAttributePlugin);
// Copy static styles as is
eleventyConfig.addPassthroughCopy("public/css");
// Copy static documents as is
eleventyConfig.addPassthroughCopy("public/pdf");
// Required to support --pathprefix
eleventyConfig.addPlugin(EleventyHtmlBasePlugin);
// Internationalization
eleventyConfig.addPlugin(EleventyI18nPlugin, {
defaultLanguage: "fr",
});
// RSS feed
eleventyConfig.addPlugin(feedPlugin, {
type: "rss",
outputPath: "/feed.xml",
collection: {
name: "blog"
}
})
// Code snippets with syntax highlighting
eleventyConfig.addPlugin(syntaxHighlight, {
lineSeparator: "\n",
errorOnInvalidLanguage: true,
alwaysWrapLineHighlights: true,
preAttributes: {},
codeAttributes: {}
});
// Create images variants of different dimensions and different formats.
// They will be loaded depending on the viewport
eleventyConfig.addPlugin(eleventyImageTransformPlugin, {
outputDir: "./_site/public/img/",
urlPath: "/public/img/",
extensions: "html",
// output image formats
formats: ["webp", "auto"],
// output image widths
widths: ["280", "580", "920", "auto"],
// attributes assigned on <img> override these values.
defaultAttributes: {
loading: "lazy",
decoding: "async",
sizes: `100vw`,
},
sharpOptions: {
animated: true,
},
sharpPngOptions: {
palette: true,
colours: 32,
},
sharpWebpOptions: {
quality: 50,
alphaQuality: 50,
lossless: false,
nearLossless: false,
smartSubsample: false,
effort: 4, // CPU effort, between 0 (fastest) and 6 (slowest)
},
})
// Support yaml data files : https://www.11ty.dev/docs/data-custom/#yaml
eleventyConfig.addDataExtension("yml", (contents) => yaml.load(contents));
}