-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
68 lines (56 loc) · 2.12 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
const htmlmin = require("html-minifier");
module.exports = function(eleventyConfig) {
eleventyConfig.addWatchTarget("./src/assets/");
eleventyConfig.addPassthroughCopy("./src/assets/");
eleventyConfig.setBrowserSyncConfig({
files: "./public/css/**/*.css"
});
// Sort sections by file name (`fileSlug`)
eleventyConfig.addCollection("sortedSections", function(collectionApi) {
const sections = collectionApi.getFilteredByTag("sections");
return [...sections].sort((a, b) => {
return a.fileSlug.localeCompare(b.fileSlug);
});
});
eleventyConfig.addCollection("sortedProjects", function(collectionApi) {
const projects = collectionApi.getFilteredByTag("projects");
return [...projects].sort((a, b) => {
return a.fileSlug.localeCompare(b.fileSlug);
});
});
// Thanks, https://charliepark.org/smartquotes_in_eleventy/
eleventyConfig.addFilter("smartquotes", (post) => {
const hawaii = new RegExp(/(?<=<(h|l|p[^r]).*)Hawai'i/g);
const slang = new RegExp(/'(cause|em|til|twas)/g);
const apostrophes = new RegExp(/(?<=<(h|l|p[^r]).*)\b'\b/g);
const years = new RegExp(/(?<=\s)'(?=\d)/g);
const openDoubles = new RegExp(/(?<=<(h|l|p[^r]).*)(?<=\s|>)"/g);
const closeDoubles = new RegExp(/(?<=<(h|l|p[^r]).*“.*)"(?=(\s|\p{P}|<))/gu);
const openSingles = new RegExp(/(?<=<(h|l|p[^r]).*)(?<=\s|>)'/g);
const closeSingles = new RegExp(/(?<=<(h|l|p[^r]).*‘.*)'(?=(\s|\p{P}|<))/gu);
return post
.replace(hawaii, "Hawaiʻi").replace(slang, "’$1")
.replace(apostrophes, "’").replace(years, "’")
.replace(openDoubles, "“").replace(closeDoubles, "”")
.replace(openSingles, "‘").replace(closeSingles, "’")
.replace(/\.\.\./g, "…");
});
// https://www.11ty.dev/docs/config/#transforms-example-minify-html-output
eleventyConfig.addTransform("htmlmin", function(content) {
if (this.outputPath && this.outputPath.endsWith(".html")) {
const minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true
});
return minified;
}
return content;
});
return {
dir: {
input: "src",
output: "public"
}
};
};