-
-
Notifications
You must be signed in to change notification settings - Fork 296
/
.eleventy.js
82 lines (71 loc) · 1.85 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
const esbuild = require("esbuild");
const htmlmin = require("html-minifier");
const md = require("markdown-it")();
const Image = require("@11ty/eleventy-img");
async function imageShortcode(
src,
cls,
alt,
widths = [600],
outputDir = "./_site/static/thumbnails/",
urlPath = "/static/thumbnails/",
sizes = "(min-width: 30em) 50vw, 100vw"
) {
let metadata = await Image(src, {
widths,
formats: ["jpeg", "webp"],
outputDir,
urlPath,
});
let imageAttributes = {
class: cls,
alt,
sizes,
loading: "lazy",
decoding: "async",
};
return Image.generateHTML(metadata, imageAttributes);
}
/** @param {import("@11ty/eleventy").UserConfig} eleventyConfig */
module.exports = (eleventyConfig) => {
eleventyConfig.on("eleventy.before", async function () {
await esbuild.build({
minify: true,
entryPoints: ["src/static/js/index.js"],
bundle: true,
outfile: "_site/static/js/bundle.js",
sourcemap: false,
target: ["es2017"],
});
});
eleventyConfig.addPassthroughCopy("src/static/img");
eleventyConfig.addPassthroughCopy("src/screenshots");
eleventyConfig.addAsyncShortcode("image", imageShortcode);
eleventyConfig.addFilter("markdownIt", function (value) {
return md.render(value);
});
eleventyConfig.addFilter("bustCache", (url) => {
const buildEpoch = Date.now();
return `${url}?${buildEpoch}`;
});
eleventyConfig.addTransform("htmlmin", function (content) {
if (
process.env.ELEVENTY_ENV === "production" &&
this.page.outputPath &&
this.page.outputPath.endsWith(".html")
) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true,
});
return minified;
}
return content;
});
return {
dir: {
input: "src",
},
};
};