-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheleventy.config.js
116 lines (103 loc) · 3.03 KB
/
eleventy.config.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
import fs from "fs-extra";
import htmlmin from "html-minifier";
import markdownIt from "markdown-it";
import markdownItAnchor from "markdown-it-anchor";
import pluginWebC from "@11ty/eleventy-plugin-webc";
import postcss from "postcss";
import postcssImport from "postcss-import";
import postcssNested from "postcss-nested";
import postcssEach from "postcss-each";
import autoprefixer from "autoprefixer";
import syntaxHighlight from "@11ty/eleventy-plugin-syntaxhighlight";
import { eleventyImageTransformPlugin } from "@11ty/eleventy-img";
export default function (eleventyConfig) {
// Plugins
eleventyConfig.addPlugin(pluginWebC, {
components: "src/_includes/**/*.webc"
});
eleventyConfig.addPlugin(eleventyImageTransformPlugin, {
formats: ["avif", "webp"],
widths: [320, 640],
dryRun: true,
htmlOptions: {
imgAttributes: {
decoding: "async",
fetchPriority: "high",
loading: "lazy",
sizes: "(min-width: 36em) 33.3vw, 100vw"
}
},
urlFormat: ({ src, width, format }) =>
`${src}${format !== "svg" ? `?fm=${format}&w=${width}` : ""}`
});
eleventyConfig.addPlugin(syntaxHighlight);
// Make CSS mo-betta
eleventyConfig.addTemplateFormats("css");
eleventyConfig.addExtension("css", {
outputFileExtension: "css",
compile: async function (inputContent) {
const result = await postcss([
postcssImport,
postcssNested,
postcssEach,
autoprefixer
]).process(inputContent, { from: undefined, to: undefined });
return async () => result.css;
}
});
// Filters
eleventyConfig.addFilter("filteredProject", (arr, value) => {
return arr.find((project) => project.name === value);
});
// Markdown support
let markdownLibrary = markdownIt({
html: true,
breaks: true,
linkify: true
}).use(markdownItAnchor, {
renderHref: false,
tabIndex: false
});
eleventyConfig.setLibrary("md", markdownLibrary);
// 404 handling
eleventyConfig.setBrowserSyncConfig({
callbacks: {
ready: (err, bs) => {
bs.addMiddleware("*", (req, res) => {
const content_404 = fs.readFileSync("_site/404.html");
console.log(content_404);
res.writeHead(404, { "Content-Type": "text/html; charset=UTF-8" });
res.write(content_404);
res.end();
});
}
}
});
// HTML minification
eleventyConfig.addTransform("htmlmin", function (content, outputPath) {
if (outputPath && outputPath.endsWith(".html")) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true
});
return minified;
}
return content;
});
// Passthrough static stuffs
eleventyConfig.addPassthroughCopy({
static: "/"
});
eleventyConfig.setServerPassthroughCopyBehavior("copy");
return {
dir: {
input: "src",
includes: "_includes",
layouts: "layouts",
data: "data",
output: "dist"
},
markdownTemplateEngine: "njk"
};
}