-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
127 lines (106 loc) · 3.44 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
import directoryOutputPlugin from "@11ty/eleventy-plugin-directory-output";
import eleventySass from "@11tyrocks/eleventy-plugin-sass-lightningcss";
import xmlFiltersPlugin from "eleventy-xml-plugin";
import { minify } from "html-minifier-terser";
import markdownIt from "markdown-it";
import markdownItAttrs from "markdown-it-attrs";
import mila from "markdown-it-link-attributes";
import blockquote from "./src/11ty/components/blockquote.js";
import images from "./src/11ty/components/images.js";
process.setMaxListeners(50);
export default function(eleventyConfig) {
// DON'T USE .GITIGNORE
eleventyConfig.setUseGitIgnore(false);
eleventyConfig.addFilter("addNbsp", (str) => {
if (!str) {
return;
}
let title = str.replace(/((.*)\s(.*))$/g, "$2 $3");
title = title.replace(/"(.*)"/g, '\\"$1\\"');
return title;
});
// https://spencermortensen.com/articles/email-obfuscation/#link-url
eleventyConfig.addFilter("encode", (text) => {
let code = '';
for (let i = 0; i < text.length; ++i) {
code += '%' + text.charCodeAt(i).toString(16);
}
return code;
})
// SHORTCODE
eleventyConfig.addShortcode("year", () => {
let year = new Date().getFullYear();
return year.toString(); // or `return String(year);`
});
eleventyConfig.addShortcode("images", images);
// {% images "path_to_image", "alt_text", "class", "subclass" %}
eleventyConfig.addPairedShortcode("blockquote", blockquote);
// {% blockquote "Lorem Ipsum" %}
// Vestibulum id ligula porta felis euismod semper.
// {% endblockquote %}
// MARKDOWN SETTINGS
const markdownItOptions = {
html: true,
linkify: true,
typographer: true,
};
const markdownItAttrsOptions = {
leftDelimiter: "{",
rightDelimiter: "}",
allowedAttributes: ["id", "class", /^data-.*$/],
};
const milaOptions = {
pattern: /^https:/,
attrs: {
target: "_blank",
rel: "noopener",
},
};
const markdown = markdownIt(markdownItOptions)
.use(markdownItAttrs, markdownItAttrsOptions)
.use(mila, milaOptions);
eleventyConfig.setLibrary("md", markdown);
// PLUGINS
eleventyConfig.addPlugin(xmlFiltersPlugin);
eleventyConfig.addPlugin(directoryOutputPlugin);
// LAYOUT ALIASES
eleventyConfig.addLayoutAlias("default", "layouts/default.liquid");
eleventyConfig.addLayoutAlias("home", "layouts/home.liquid");
eleventyConfig.addLayoutAlias("post", "layouts/post.liquid");
eleventyConfig.addLayoutAlias("page", "layouts/page.liquid");
eleventyConfig.addLayoutAlias("404", "layouts/404.liquid");
// PASSTHROUGHT ELEMENTS
eleventyConfig.addPassthroughCopy({
"src/root/*": "/",
"src/root/assets/fonts/*": "/assets/fonts/",
"src/portfolio-static/root/*": "/",
"src/portfolio-static/assets/images/noise.webp": "/assets/images/noise.webp",
"src/portfolio-static/assets/images/thumbnail.png": "/assets/images/thumbnail.png",
"src/portfolio-static/assets/videos/*" : "/assets/videos"
});
// SERVER OPTIONS
eleventyConfig.setServerPassthroughCopyBehavior("passthrough");
eleventyConfig.addWatchTarget("**/*.(scss|liquid|md)");
// MINIFY SASS
eleventyConfig.addPlugin(eleventySass);
// MINIFY HTML
eleventyConfig.addTransform("htmlmin", function(content) {
if (this.page.outputPath && this.page.outputPath.endsWith(".html")) {
let minified = minify(content, {
options: {
removeComments: true,
collapseWhitespace: true,
},
});
return minified;
}
return content;
});
return {
dir: {
data: "_data",
input: "src",
output: "dist",
},
};
};