-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.eleventy.js
88 lines (78 loc) · 2.46 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
const excerpt = require("eleventy-plugin-excerpt");
const fs = require("fs");
const inclusiveLangPlugin = require("@11ty/eleventy-plugin-inclusive-language");
const markdownIt = require("markdown-it");
const pluginRss = require("@11ty/eleventy-plugin-rss");
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const timeToRead = require("eleventy-plugin-time-to-read");
const PASSTHROUGH_ITEMS = [
"assets",
"images",
"humans.txt",
"CNAME",
"favicon.ico",
"favicon-16x16.png",
"favicon-32x32.png",
"apple-touch-icon.png",
"android-chrome-192x192.png",
"android-chrome-512x512.png",
"site.webmanifest"
];
const MARKDOWN_OPTIONS = {
html: true,
breaks: false,
linkify: true,
typographer: true,
};
module.exports = (eleventyConfig) => {
const markdownLibrary = markdownIt(MARKDOWN_OPTIONS);
eleventyConfig.setLibrary("md", markdownLibrary);
PASSTHROUGH_ITEMS.forEach((item) => {
eleventyConfig.addPassthroughCopy(item);
});
eleventyConfig.addPlugin(excerpt);
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPlugin(inclusiveLangPlugin);
eleventyConfig.addPlugin(timeToRead);
eleventyConfig.setBrowserSyncConfig({
files: "./_site/assets/css/*.css",
callbacks: {
ready: function (err, bs) {
bs.addMiddleware("*", (req, res) => {
const content_404 = fs.readFileSync("_site/404.html");
// Add 404 http status code in request header.
res.writeHead(404, { "Content-Type": "text/html; charset=UTF-8" });
// Provides the 404 content without redirect.
res.write(content_404);
res.end();
});
},
},
});
eleventyConfig.addCollection("posts", function (collectionApi) {
return collectionApi.getFilteredByGlob("blog/_posts/*.md");
});
eleventyConfig.addCollection("personalPosts", function (collectionApi) {
return collectionApi.getFilteredByGlob("life/_posts/*.md");
});
eleventyConfig.addLiquidFilter("array_to_sentence_string", function (list) {
if (list.length === 1) {
return list[0];
}
if (list.length === 2) {
return list.join(" and ");
}
const lastWord = list.splice(list.length - 1, 1);
return list.join(", ") + ", and " + lastWord[0];
});
return {
dir: {
input: "./",
output: "./_site",
layouts: "./_layouts",
},
passthroughFileCopy: true,
templateFormats: ["html", "liquid", "md", "njk"],
};
};