-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.eleventy.js
More file actions
150 lines (128 loc) · 4.24 KB
/
.eleventy.js
File metadata and controls
150 lines (128 loc) · 4.24 KB
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 { DateTime } from "luxon";
import CleanCSS from "clean-css";
import UglifyJS from "uglify-js";
import htmlmin from "html-minifier";
import markdownIt from "markdown-it";
import markdownItAttrs from "markdown-it-attrs";
import markdownItAnchor from "markdown-it-anchor";
import eleventyNavigationPlugin from "@11ty/eleventy-navigation";
import { eleventyImageTransformPlugin } from "@11ty/eleventy-img";
import fontAwesomePlugin from "@11ty/font-awesome";
import bundlePlugin from "@11ty/eleventy-plugin-bundle";
// import addPairedShortcode from "";
export default function(eleventyConfig) {
// Eleventy Image Plugin https://www.11ty.dev/docs/plugins/image/
eleventyConfig.addPlugin(eleventyImageTransformPlugin)
// Eleventy Navigation https://www.11ty.dev/docs/plugins/navigation/
eleventyConfig.addPlugin(eleventyNavigationPlugin);
// Add Bundle Plugin
eleventyConfig.addPlugin(bundlePlugin);
// Font Awesome Plugin
eleventyConfig.addPlugin(fontAwesomePlugin);
// Merge data instead of overriding
// https://www.11ty.dev/docs/data-deep-merge/
eleventyConfig.setDataDeepMerge(true);
// Blog posts collection
eleventyConfig.addCollection("post", collection => {
return collection.getFilteredByGlob("posts/*.md").reverse();
});
// Add support for maintenance-free post authors
eleventyConfig.addCollection("authors", collection => {
const blogs = collection.getFilteredByGlob("posts/*.md");
return blogs.reduce((coll, post) => {
const author = post.data.author;
if (!author) {
return coll;
}
if (!coll.hasOwnProperty(author)) {
coll[author] = [];
}
coll[author].push(post.data);
return coll;
}, {});
});
// Date formatting (human readable)
eleventyConfig.addFilter("readableDate", dateObj => {
return DateTime.fromJSDate(dateObj).toFormat("dd LLL yyyy");
});
// Date formatting (machine readable)
eleventyConfig.addFilter("machineDate", dateObj => {
return DateTime.fromJSDate(dateObj).toFormat("yyyy-MM-dd");
});
// Date for Current Year
eleventyConfig.addFilter("currentYear", () => {
return new Date().getFullYear();
});
// Extract headings for table of contents
eleventyConfig.addFilter("extractHeadings", function(content) {
const headingRegex = /<h([2-4])[^>]*id="([^"]*)"[^>]*>(.*?)<\/h\1>/g;
const headings = [];
let match;
while ((match = headingRegex.exec(content)) !== null) {
headings.push({
level: parseInt(match[1]),
id: match[2],
text: match[3].replace(/<[^>]*>/g, '').replace(/&/g, '&')
});
}
return headings;
});
// Minify CSS
eleventyConfig.addFilter("cssmin", function(code) {
return new CleanCSS({}).minify(code).styles;
});
// Minify JS
eleventyConfig.addFilter("jsmin", function(code) {
let minified = UglifyJS.minify(code);
if (minified.error) {
console.log("UglifyJS error: ", minified.error);
return code;
}
return minified.code;
});
// Minify HTML output
eleventyConfig.addTransform("htmlmin", function(content, outputPath) {
if (outputPath.indexOf(".html") > -1) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true
});
return minified;
}
return content;
});
// Don't process folders with static assets e.g. images
eleventyConfig.addPassthroughCopy("favicon.ico");
eleventyConfig.addPassthroughCopy("static/img");
eleventyConfig.addPassthroughCopy("admin");
eleventyConfig.addPassthroughCopy("_includes/assets/css/inline.css");
eleventyConfig.addPassthroughCopy("static/js");
/* Markdown Plugins */
let options = {
html: true,
breaks: true,
linkify: true
};
let opts = {
permalink: false,
level: [2, 3, 4] // Generate anchors for h2, h3, h4
};
eleventyConfig.setLibrary("md", markdownIt(options)
.use(markdownItAnchor, opts)
.use(markdownItAttrs)
);
return {
templateFormats: ["md", "njk", "html", "liquid"],
pathPrefix: "/",
markdownTemplateEngine: "liquid",
htmlTemplateEngine: "njk",
dataTemplateEngine: "njk",
dir: {
input: ".",
includes: "_includes",
data: "_data",
output: "_site"
}
};
};