-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
111 lines (94 loc) · 2.7 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
const fs = require("fs");
const cleanCSS = require("clean-css");
const htmlmin = require("html-minifier");
const markdown = require("markdown-it");
const anchor = require("markdown-it-anchor");
const OUTPUT_DIRECTORY_NAME = "dist";
fs.rmSync(OUTPUT_DIRECTORY_NAME, {
force: true,
recursive: true,
});
module.exports = (config) => {
// Copying files
config.addPassthroughCopy("src/assets/**/*.{webmanifest,png,svg}");
config.addPassthroughCopy({ "src/assets/**/*.ico": "/" });
// Shortcodes
config.addPairedShortcode("logo", (title, homeUrl, isHomePage) => {
if (isHomePage) {
return `<span class="header__logo header__logo--text">
${title}
</span>`;
}
return `<a href="${homeUrl}" class="header__logo">
${title}
</a>`;
});
config.addPairedShortcode("codeblock", (snippet, language, file) => {
if (file === undefined) {
return `<figure aria-label="A block of code" class="code-block">
<figcaption class="code-block__header code-header">
<dl class="code-header__info">
<dt class="visually-hidden">Language</dt>
<dd class="code-header__language">${language}</dd>
</dl>
</figcaption>
${snippet}</figure>`;
}
return `<figure aria-label="A block of code" class="code-block">
<figcaption class="code-block__header code-header">
<dl class="code-header__info">
<dt class="visually-hidden">Language</dt>
<dd class="code-header__language">${language}</dd>
<dt class="visually-hidden">File</dt>
<dd class="code-header__file">${file}</dd>
</dl>
</figcaption>
${snippet}</figure>`;
});
// Libraries
const markdownLibrary = markdown({
// Otherwise shortcodes don't work
html: true,
}).use(anchor, {
permalink: anchor.permalink.headerLink(),
});
config.setLibrary("md", markdownLibrary);
// Filters
config.addFilter("date", (dateString) => {
const date = new Date(dateString);
return date.toLocaleString("en", {
year: "numeric",
month: "long",
day: "numeric",
});
});
// Minify HTML
config.addTransform("htmlmin", (content, outputPath) => {
if (outputPath?.endsWith(".html")) {
const minifiedHTML = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true,
});
return minifiedHTML;
}
return content;
});
// Minify and inline CSS
config.addFilter("cssmin", (code) => {
return new cleanCSS({}).minify(code).styles;
});
return {
dataTemplateEngine: "njk",
dir: {
data: "data",
includes: "includes",
input: "src",
layouts: "layouts",
output: OUTPUT_DIRECTORY_NAME,
},
htmlTemplateEngine: "njk",
markdownTemplateEngine: "njk",
templateFormats: ["md", "njk"],
};
};