-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path.eleventy.js
179 lines (149 loc) · 5.84 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
const yaml = require("js-yaml");
const { DateTime } = require("luxon");
// const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const timeToRead = require("eleventy-plugin-time-to-read");
const lazyImagesPlugin = require("eleventy-plugin-lazyimages");
const htmlmin = require("html-minifier");
const searchFilter = require("./src/filters/searchFilter");
const markdownIt = require("markdown-it");
const markdownItMark = require("markdown-it-mark");
const markdownItFootnote = require("markdown-it-footnote");
module.exports = function (eleventyConfig) {
// overwrite markdown-it options
let options = {
html: true,
breaks: true
};
eleventyConfig.setLibrary("md", markdownIt(options));
// support ==content== to <mark>content</mark>
eleventyConfig.amendLibrary("md", mdLib => mdLib.use(markdownItMark));
eleventyConfig.amendLibrary("md", mdLib => mdLib.use(markdownItFootnote));
// Disable automatic use of your .gitignore
eleventyConfig.setUseGitIgnore(false);
// instead of overriding, merge data cascade (e.g. frontmatter) between templates & files (doc: https://www.11ty.dev/docs/data-deep-merge/)
eleventyConfig.setDataDeepMerge(true);
// 404 page sync when eleventy --serve.
// https://www.11ty.dev/docs/quicktips/not-found/
// Current Year (global custom data, doc: https://www.11ty.dev/docs/data-global-custom/)
eleventyConfig.addGlobalData(
"currentYear",
async () => {
return (new Date()).getFullYear();
}
);
// human readable date
eleventyConfig.addFilter("readableDate", (dateObj) => {
return DateTime.fromJSDate(dateObj, { zone: "utc" }).toFormat("DD");
});
// date to yyyy-MM-dd
eleventyConfig.addFilter("dateFormat", (dateObj) => {
return DateTime.fromJSDate(dateObj, { zone: "utc" }).toFormat("yyyy-MM-dd");
});
// search
eleventyConfig.addFilter("search", searchFilter);
eleventyConfig.addCollection("post", collection => {
return [...collection.getFilteredByGlob("./src/collections/post/*.md")];
});
// Syntax Highlighting for Code blocks
// eleventyConfig.addPlugin(syntaxHighlight);
// Time to read content
eleventyConfig.addPlugin(timeToRead);
// Image Lazy Loading
eleventyConfig.addPlugin(lazyImagesPlugin, {
imgSelector: ".single-article img", // only post images
// preferNativeLazyLoad: false,
// cacheFile: '', // Pass an empty string to turn off the cache.
});
// To Support .yaml Extension in _data (more readable)
// You may remove this if you prefer JSON
eleventyConfig.addDataExtension("yaml", (contents) =>
yaml.safeLoad(contents)
);
// Add Tailwind Output CSS as Watch Target
eleventyConfig.addWatchTarget("./src/static/css/main.scss");
// Copy Static Files to /_Site
eleventyConfig.addPassthroughCopy({
"./src/static/fonts/*": "./static/fonts/",
"./src/admin/config.yml": "./admin/config.yml",
"./src/static/js/footer.js": "./static/js/footer.js",
"./src/static/js/search.js": "./static/js/search.js",
"./src/static/js/elasticlunr.min.js": "./static/js/elasticlunr.min.js",
});
// Katex Files (CSS use CDN)
eleventyConfig.addPassthroughCopy({
"./node_modules/katex/dist/katex.min.js": "./static/js/katex.min.js",
"./node_modules/katex/dist/contrib/auto-render.min.js":
"./static/js/auto-render.min.js",
});
// TOC Files (CSS use CDN)
eleventyConfig.addPassthroughCopy({
"./src/static/js/toc.js": "./static/js/toc.js",
});
// PrismJS Files
eleventyConfig.addPassthroughCopy({
"./src/static/css/lib/prism.css": "./static/css/prism.css", // customized
// "./node_modules/prismjs/themes/prism-tomorrow.css": "./static/css/prism.css", // only for basic languages
"./node_modules/prismjs/plugins/line-numbers/prism-line-numbers.css":
"./static/css/prism-line-numbers.css",
"./node_modules/prismjs/plugins/line-numbers/prism-line-numbers.min.js":
"./static/js/prism-line-numbers.min.js",
"./src/static/js/prism.js": "./static/js/prism.js",
});
// Copy Image Folder to /_site
eleventyConfig.addPassthroughCopy("./src/static/img");
// Copy favicon to route of /_site
eleventyConfig.addPassthroughCopy("./src/favicon.ico");
// Custom Filter: split()
eleventyConfig.addFilter("split", function (str, seperator) {
return str.split(seperator);
});
// Custom Filter: includes()
eleventyConfig.addFilter("includes", function (array, item) {
return array.includes(item);
});
// Custom Filter: substring()
eleventyConfig.addFilter("substring", function (str, start, end) {
return str.substring(start, end);
});
// Custom Filter: indexOf()
eleventyConfig.addFilter("indexOf", function (array, indexItem) {
return array.indexOf(indexItem);
});
// // Custom Filter: push()
// eleventyConfig.addFilter("push", function(array, item) {
// return array.push(item);
// });
// // Custom Filter: pop()
// eleventyConfig.addFilter("pop", function(array, item) {
// return array.pop(item);
// });
// Minify HTML
eleventyConfig.addTransform("htmlmin", function (content, outputPath) {
// Eleventy 1.0+: use this.inputPath and this.outputPath instead
if (outputPath.endsWith(".html")) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true,
});
return minified;
}
return content;
});
return {
dir: {
// input directory
input: "src",
// ⚠️ These values are relative to input directory, i.e.: src/
includes: "_includes",
layouts: "_includes/layouts",
data: "_data", // global data files
// output directory
output: "_site",
},
// Let Eleventy transform HTML files as nunjucks, so we can use .html instead of .njk
htmlTemplateEngine: "njk",
// use njk as the default template engine for .md files
markdownTemplateEngine: "njk"
};
};