-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
.eleventy.js
112 lines (100 loc) · 3.52 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
const collections = require("./src/_11ty/collections");
const filters = require("./src/_11ty/filters");
const shortcodes = require("./src/_11ty/shortcodes");
const Terser = require("terser");
const slugify = require("slugify");
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const pluginRss = require("@11ty/eleventy-plugin-rss");
const markdownIt = require("markdown-it");
const markdownItAnchor = require("markdown-it-anchor");
const openInCodepen = require("@11tyrocks/eleventy-plugin-open-in-codepen");
const socialImages = require("@11tyrocks/eleventy-plugin-social-images");
const pluginTOC = require("eleventy-plugin-toc");
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(pluginTOC, { tags: ["h2"] });
eleventyConfig.addPlugin(socialImages);
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPlugin(openInCodepen, {
siteUrl: "ModernCSS.dev",
siteTitle: "Modern CSS Solutions",
siteTag: "moderncss",
buttonClass: "button",
buttonIconClass: "button__icon",
});
eleventyConfig.addWatchTarget("./src/sass/");
eleventyConfig.addPassthroughCopy("./src/fonts");
eleventyConfig.addPassthroughCopy("./src/img");
eleventyConfig.addPassthroughCopy("./src/favicon.png");
eleventyConfig.addPassthroughCopy("./src/robots.txt");
eleventyConfig.addPassthroughCopy("./src/_redirects");
eleventyConfig.addPassthroughCopy("./_headers");
// Collections: /src/_11ty/collections.js
Object.keys(collections).forEach((collectionName) => {
eleventyConfig.addCollection(collectionName, collections[collectionName]);
});
// Filters: /src/_11ty/filters.js
Object.keys(filters).forEach((filterName) => {
eleventyConfig.addFilter(filterName, filters[filterName]);
});
eleventyConfig.addNunjucksAsyncFilter("jsmin", async (code, callback) => {
try {
const minified = await Terser.minify(code);
return callback(null, minified.code);
} catch (err) {
console.error("Error during terser minify:", err);
return callback(err, code);
}
});
// Shortcodes: /src/config/shortcodes.js
Object.keys(shortcodes).forEach((shortcodeName) => {
eleventyConfig.addShortcode(shortcodeName, shortcodes[shortcodeName]);
});
// https://11ty.rocks/eleventyjs/slugs-anchors/#enable-anchor-links-on-content-headings
const linkAfterHeader = markdownItAnchor.permalink.linkAfterHeader({
class: "anchor",
symbol: "<span hidden>#</span>",
style: "aria-labelledby",
});
const markdownItAnchorOptions = {
level: [1, 2, 3],
slugify: (str) =>
slugify(str, {
lower: true,
strict: true,
remove: /["]/g,
}),
tabIndex: false,
permalink(slug, opts, state, idx) {
state.tokens.splice(
idx,
0,
Object.assign(new state.Token("div_open", "div", 1), {
// Add class "header-wrapper [h1 or h2 or h3]"
attrs: [["class", `heading-wrapper ${state.tokens[idx].tag}`]],
block: true,
})
);
state.tokens.splice(
idx + 4,
0,
Object.assign(new state.Token("div_close", "div", -1), {
block: true,
})
);
linkAfterHeader(slug, opts, state, idx + 1);
},
};
/* Markdown Overrides */
let markdownLibrary = markdownIt({
html: true,
}).use(markdownItAnchor, markdownItAnchorOptions);
eleventyConfig.setLibrary("md", markdownLibrary);
return {
passthroughFileCopy: true,
dir: {
input: "src",
output: "public",
},
};
};