-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
138 lines (120 loc) · 4.08 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
// https://www.aleksandrhovhannisyan.com/blog/useful-11ty-filters/#custom-filters-for-any-11ty-project
// https://www.aleksandrhovhannisyan.com/tags/11ty/
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const PostCSSPlugin = require("eleventy-plugin-postcss");
const markdownIt = require("markdown-it");
const markdownItAnchor = require('markdown-it-anchor');
const markdownItContainer = require('markdown-it-container');
const markdownItAttrs = require('markdown-it-attrs');
const htmlmin = require('html-minifier');
const eleventyNavigationPlugin = require("@11ty/eleventy-navigation");
const { DateTime } = require("luxon");
const pluginTOC = require('eleventy-plugin-toc');
const eleventyPluginFilesMinifier = require("@sherby/eleventy-plugin-files-minifier");
module.exports = function(eleventyConfig) {
// Pour les GH pages : https://www.11ty.dev/docs/config/#deploy-to-a-subdirectory-with-a-path-prefix
// return {
// pathPrefix: "/eleventy-base-blog/"
// }
eleventyConfig.addPlugin(eleventyNavigationPlugin);
eleventyConfig.addPlugin(PostCSSPlugin);
eleventyConfig.addPlugin(pluginTOC);
eleventyConfig.addPlugin(syntaxHighlight, {
// alwaysWrapLineHighlights: true,
});
/* Options MD */
// Codepen embeds
// Multiline Content with Parameter
eleventyConfig.addShortcode("livecode", function(href, defaultTab) {
const cpUrl = `https://codepen.io/shinze/embed/preview/${href}?default-tab=${defaultTab}%2Cresult&editable=true`;
const alternative = `
<a href="https://codepen.io/shinze/pen/${href}">Accéder au document sur codepen</a>
`
return `
<div className="livecode">
<iframe src="${cpUrl}" frameborder="no" loading="lazy" allowtransparency="true"
allowfullscreen="true"
height="500"
class="livecode-iframe"
scrolling="no">
${alternative}
</iframe>
</div>
`;
});
/**
* Flatten a navigation object into an array, and add "next" and "prev"
* properties.
* More : https://github.com/11ty/eleventy-navigation/issues/22
*/
eleventyConfig.addFilter('flattenNavigationAndAddNextPrev', (nav) => {
const flat = [];
const visit = (items) => {
for (const item of items) {
flat.push(item);
visit(item.children);
}
};
visit(nav);
for (let i = 0; i < flat.length; i++) {
const item = flat[i];
item.prev = flat[i - 1];
item.next = flat[i + 1];
}
return flat;
});
let mdOptions = {
html: true,
breaks: true,
linkify: true,
quotes: ['«\xA0', '\xA0»', '‹\xA0', '\xA0›'],
};
eleventyConfig.setLibrary("md", markdownIt(mdOptions)
.use(markdownItAttrs)
.use(markdownItAnchor)
// https://davidea.st/articles/11ty-tips-i-wish-i-knew-from-the-start/
// Callout
.use(markdownItContainer, 'dynamic', {
validate: function () { return true; },
render: function (tokens, idx) {
const token = tokens[idx];
if (token.nesting === 1) {
return '<div class="' + token.info.trim() + '">';
} else {
return '</div>';
}
}
})
);
// Simply copy assets to public
eleventyConfig.addPassthroughCopy("source/styles.css");
eleventyConfig.addPassthroughCopy("source/img");
eleventyConfig.addPassthroughCopy("source/js");
// Minification : https://www.benjaminrancourt.ca/how-to-minify-your-eleventy-build/
eleventyConfig.addPlugin(eleventyPluginFilesMinifier);
eleventyConfig.addTransform('htmlmin', (content, outputPath) => {
if (outputPath.endsWith('.html')) {
const minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true,
minifyJS: true,
html5: true,
removeEmptyElements: true,
});
return minified;
}
return content;
});
// Return your Object options:
return {
dir: {
input: "source",
output: "public"
},
templateFormats: ["md", "njk"],
markdownTemplateEngine: "njk",
htmlTemplateEngine: "njk",
dataTemplateEngine: "njk",
};
};