-
Notifications
You must be signed in to change notification settings - Fork 0
/
eleventy.config.js
87 lines (75 loc) · 3.24 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
const path = require("path");
const fs = require('node:fs');
const pluginBundle = require("@11ty/eleventy-plugin-bundle");
const pluginNavigation = require("@11ty/eleventy-navigation");
const { EleventyHtmlBasePlugin } = require("@11ty/eleventy");
const prettier = require("prettier");
const { PurgeCSS } = require("purgecss");
const pluginImages = require("./eleventy.config.images.js");
module.exports = function (eleventyConfig) {
eleventyConfig.addPassthroughCopy({
"content/img/": "/img",
"content/**/portfolio-*.jpg": "/img",
"node_modules/bootstrap-icons/font/fonts": "/css/fonts",
"node_modules/bootstrap-icons/font/bootstrap-icons.min.css": "/css/fonts.css",
"node_modules/bootstrap/dist/css/bootstrap.min.css": "/css/main.css",
"node_modules/bootstrap/dist/js/bootstrap.min.js": "/js/main.js"
});
eleventyConfig.addPassthroughCopy("content/resume/**/*.{pdf,jpg,jpeg,png}");
eleventyConfig.addPassthroughCopy("content/portfolio/creative-talents/essay-certificate.jpg");
eleventyConfig.addPassthroughCopy("content/portfolio/**/*.{pdf,mp4}");
eleventyConfig.addWatchTarget("content/**/*.{md,svg,webp,png,jpeg}");
eleventyConfig.addPlugin(pluginImages);
eleventyConfig.addPlugin(pluginNavigation);
eleventyConfig.addPlugin(EleventyHtmlBasePlugin);
eleventyConfig.addPlugin(pluginBundle);
eleventyConfig.addFilter("exclude", (arr, match) => {
const matchLower = match ? match.toLowerCase() : '';
return arr.filter(str => str.toLowerCase() !== matchLower);
});
eleventyConfig.addTransform("prettier", (content, outputPath) => {
const extname = path.extname(outputPath);
switch (extname) {
case ".html":
case ".json":
const parser = extname.replace(/^./, "");
return prettier.format(content, { parser });
default:
return content;
}
});
eleventyConfig.on('eleventy.after', async ({ dir, results, runMode, outputMode }) => {
// Purge CSS only on build, not watch or serve
if (runMode === "build") {
const purgeCSSResult = await new PurgeCSS().purge({
content: [`${dir.output}/**/*.html`],
css: [`${dir.output}/**/*.css`],
variables: true,
safelist: ['modal-backdrop']
});
purgeCSSResult.forEach(async (result) => {
if (!result.rejected) {
await fs.writeFile(`${result.file}`, result.css, err => {
if (err) {
console.error(`CSS purge error writing file '${result.file}': ${err}`);
}
});
} else {
console.error(`CSS purge rejection on file: '${result.file}'`);
}
});
}
});
return {
templateFormats: ["md", "njk", "html"],
markdownTemplateEngine: "njk",
htmlTemplateEngine: "njk",
dir: {
input: "content", // default: "."
includes: "../_includes", // default: "_includes"
data: "../_data", // default: "_data"
output: "dist"
},
pathPrefix: "/",
};
};