-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
97 lines (89 loc) · 2.82 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
import markdownIt from "markdown-it";
import markdownItAnchor from "markdown-it-anchor";
import markdownItFootnote from "markdown-it-footnote";
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 filters from "./config/filters/index.js";
export default async function (eleventyConfig) {
/* plugins */
eleventyConfig.addPlugin(eleventyNavigationPlugin);
eleventyConfig.addPlugin(EleventyRenderPlugin);
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;
},
],
});
/* passtrough copy */
eleventyConfig.addPassthroughCopy("src/static");
/* collections */
eleventyConfig.addCollection("blog", function (collectionApi) {
return collectionApi.getFilteredByGlob("src/pages/blog/posts/**/*.md");
});
eleventyConfig.addCollection("slashes", function (collectionApi) {
return collectionApi.getFilteredByGlob("src/pages/slashes/*.md");
});
/* filters */
Object.keys(filters).forEach((filterName) => {
eleventyConfig.addFilter(filterName, filters[filterName]);
});
/* set markdown library */
const md = markdownIt({ html: true });
md.use(markdownItAnchor, {
permalink: markdownItAnchor.permalink.headerLink({
safariReaderFix: true,
}),
tabIndex: false,
});
md.use(markdownItFootnote);
eleventyConfig.setLibrary("md", md);
/* shortcodes */
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 "";
});
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",
layouts: "_layouts",
includes: "_includes",
data: "_data",
output: "_site",
},
};
}