-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
150 lines (135 loc) · 4.36 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
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 postcssConfig from "postcss-load-config";
import pluginTOC from "@uncenter/eleventy-plugin-toc";
import pluginRss from "@11ty/eleventy-plugin-rss";
import filters from "./config/filters.js";
export default async function (eleventyConfig) {
eleventyConfig.addPlugin(eleventyNavigationPlugin);
eleventyConfig.addPlugin(EleventyRenderPlugin);
eleventyConfig.addPlugin(pluginTOC);
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPassthroughCopy("src/public");
/* 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);
eleventyConfig.addPlugin(pluginTOC, {
tags: ["h2", "h3", "h4"],
ignoredElements: ["a"],
flat: true,
});
eleventyConfig.setFrontMatterParsingOptions({
excerpt: true,
excerpt_separator: "<!-- cut -->",
});
eleventyConfig.addPreprocessor("macro-inject", "njk,md", (data, content) => {
return (
`{%- from "util/component.njk" import component with context -%}\n` +
content
);
});
/* collections */
eleventyConfig.addCollection("latestContent", function (collectionApi) {
return collectionApi.getAll().sort(function (a, b) {
return b.date - a.date;
});
});
eleventyConfig.addCollection("posts", function (collection) {
return [
...collection.getFilteredByGlob("src/pages/posts/content/**/*.md"),
].reverse();
});
eleventyConfig.addCollection("extras", function (collection) {
let extrasContent = collection.getFilteredByGlob("src/pages/extras/*.md");
let filterExtras = extrasContent.filter(
(page) => page.fileSlug !== "extras"
);
return filterExtras.sort((a, b) => {
return a.data.sort_level - b.data.sort_level;
});
});
/* 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,
markdownTemplateEngine: "njk",
dir: {
input: "src",
includes: "_includes",
layouts: "_layouts",
data: "_data",
output: "_site",
},
};
}