-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.eleventy.js
83 lines (73 loc) · 2.68 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
const { EleventyRenderPlugin } = require("@11ty/eleventy");
// Build tools
const eleventySass = require("@grimlink/eleventy-plugin-sass");
const sass = require("sass");
const CleanCSS = require("clean-css");
const minifyHtml = require("./src/_config/minifyHtml");
const imageShortcode = require("./src/_config/image");
const dayjs = require("dayjs");
// Generators
const eleventyNavigationPlugin = require("@11ty/eleventy-navigation");
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const pluginRss = require("@11ty/eleventy-plugin-rss");
const mdIt = require("markdown-it");
const mdItExternalAnchor = require("markdown-it-external-anchor");
const sitemap = require("@quasibit/eleventy-plugin-sitemap");
// Config
const isProd = process.env.ELEVENTY_ENV === "prod";
const env = require("./src/_data/env.js");
module.exports = function (eleventyConfig) {
eleventyConfig.setQuietMode(!isProd);
eleventyConfig.setLibrary(
"md",
mdIt({
html: true,
}).use(mdItExternalAnchor, {
domain: env.url,
class: "external",
})
);
// Copy
eleventyConfig.addPassthroughCopy({
"src/**/*.{jpg,png,svg,webp}": "images",
});
// Plugins
eleventyConfig.addPlugin(EleventyRenderPlugin);
eleventyConfig.addPlugin(eleventySass, { sass, outputPath: "css" });
eleventyConfig.addPlugin(eleventyNavigationPlugin);
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPlugin(sitemap, { sitemap: { hostname: env.url } });
// Shortcodes
eleventyConfig.addNunjucksAsyncShortcode("image", imageShortcode);
eleventyConfig.addLiquidShortcode("image", imageShortcode);
eleventyConfig.addJavaScriptFunction("image", imageShortcode);
eleventyConfig.addShortcode("year", () => `${new Date().getFullYear()}`);
// Filters
eleventyConfig.addFilter(
"cssmin",
(code) => new CleanCSS({}).minify(code).styles
);
eleventyConfig.addFilter("assetUrl", (url) => url + env.hash);
eleventyConfig.addFilter("toISOString", (dateString) =>
new Date(dateString).toISOString()
);
eleventyConfig.addFilter("formatDate", (date, format) =>
dayjs(date).format(format)
);
eleventyConfig.addFilter("stringify", (value) => JSON.stringify(value));
// Minify
if (isProd) {
eleventyConfig.addTransform("minify", minifyHtml);
}
return {
dir: {
input: "src",
output: "_site",
layouts: "_layouts",
},
templateFormats: ["md", "njk", "11ty.js"],
markdownTemplateEngine: "njk",
htmlTemplateEngine: "njk",
};
};