-
Notifications
You must be signed in to change notification settings - Fork 1
/
.eleventy.js
126 lines (116 loc) · 3.67 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import markdownIt from "markdown-it";
import markdownItAnchor from "markdown-it-anchor";
import markdownItFootnote from "markdown-it-footnote";
import markdownItAttrs from "markdown-it-attrs";
import postcss from "postcss/lib/postcss";
import htmlMin from "html-minifier-terser";
import { EleventyRenderPlugin } from "@11ty/eleventy";
import eleventyNavigationPlugin from "@11ty/eleventy-navigation";
import pluginIcons from "eleventy-plugin-icons";
import postcssConfig from "postcss-load-config";
import pluginTOC from "@uncenter/eleventy-plugin-toc";
import readingTime from "eleventy-plugin-reading-time";
import filters from "./config/filters.js";
export default async function (eleventyConfig) {
eleventyConfig.addPlugin(eleventyNavigationPlugin);
eleventyConfig.addPlugin(EleventyRenderPlugin);
eleventyConfig.addPlugin(pluginIcons, {
sources: [
{
name: "phosphor",
path: "node_modules/@phosphor-icons/core/assets/fill",
},
],
});
eleventyConfig.addPlugin(pluginTOC, {
tags: ["h2", "h3", "h4"],
ignoredElements: ["a"],
flat: true,
});
eleventyConfig.addPlugin(readingTime);
eleventyConfig.addPassthroughCopy("src/static");
/* collections */
eleventyConfig.addCollection("news", function (collectionApi) {
return collectionApi.getFilteredByGlob("src/pages/news/content/*.md");
});
/* layout aliases */
eleventyConfig.addLayoutAlias("base", "base.njk");
eleventyConfig.addLayoutAlias("page", "page.njk");
eleventyConfig.addLayoutAlias("post", "post.njk");
/* filters */
Object.keys(filters).forEach((filterName) => {
eleventyConfig.addFilter(filterName, filters[filterName]);
});
/* plugins */
const md = markdownIt({ html: true });
md.use(markdownItAttrs, {
leftDelimiter: "[-",
rightDelimiter: "-]",
});
md.use(markdownItAnchor, {
permalink: markdownItAnchor.permalink.ariaHidden({
placement: "after",
class: "header-anchor",
symbol: "#",
ariaHidden: false,
}),
level: [1, 2, 3, 4],
slugify: eleventyConfig.getFilter("slugify"),
});
md.use(markdownItFootnote);
eleventyConfig.setLibrary("md", md);
/* shortcodes */
/* a way to make slots work inside content pages: https://danburzo.ro/eleventy-slotted-content/*/
const slots = {};
eleventyConfig.addGlobalData("eleventyComputed.slots", function () {
return (data) => {
const key = data.page.inputPath;
slots[key] = slots[key] || {};
return slots[key];
};
});
eleventyConfig.addPairedShortcode("slot", function (content, name) {
if (!name) throw new Error("Missing name for {% slot %} block!");
slots[this.page.inputPath][name] = content;
return "";
});
/* html and css optimization */
eleventyConfig.addBundle("css", {
transforms: [
async function (content) {
const { plugins } = await postcssConfig();
let result = await postcss(plugins).process(content, {
from: this.page.inputPath,
to: null,
});
return result.css;
},
],
});
eleventyConfig.addTransform("html-minify", (content, path) => {
if (path && path.endsWith(".html")) {
return htmlMin.minify(content, {
includeAutoGeneratedTags: false,
collapseBooleanAttributes: true,
noNewlinesBeforeTagClose: true,
collapseWhitespace: true,
decodeEntities: true,
removeComments: true,
sortAttributes: true,
sortClassName: true,
minifyCSS: true,
});
}
return content;
});
return {
passthroughFileCopy: true,
dir: {
input: "src",
includes: "_includes",
layouts: "_layouts",
data: "_data",
output: "_site",
},
};
}