-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
64 lines (55 loc) · 1.87 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
const CleanCSS = require("clean-css");
const { DateTime } = require("luxon");
const tufteMdWrapper = require("./util/tufteMdWrapper");
const fs = require("fs");
module.exports = function (eleventyConfig) {
// Copy `src/assets` to `_site/assets`
eleventyConfig.addPassthroughCopy("src/assets");
// Copy some more files to `_site`
eleventyConfig.addPassthroughCopy("src/CNAME");
eleventyConfig.addPassthroughCopy("src/robots.txt");
eleventyConfig.addPassthroughCopy("src/manifest.json");
// Asset Watch Targets
eleventyConfig.addWatchTarget("./src/assets");
/* Markdown Configuration */
let options = {
react: false,
};
// Markdown
eleventyConfig.setLibrary("md", tufteMdWrapper);
eleventyConfig.addFilter("markdown", tufteMdWrapper.render);
eleventyConfig.addFilter("markdownInline", tufteMdWrapper.renderInline);
// Date stuff
eleventyConfig.addShortcode("year", () => `${new Date().getFullYear()}`); // useful for copyright
eleventyConfig.addFilter("postDate", (dateObj) => {
return DateTime.fromJSDate(dateObj).toFormat("MMMM yyyy");
});
eleventyConfig.addFilter("lastModifiedDate", function (filepath) {
const stat = fs.statSync(filepath);
return stat.mtime.toISOString();
});
// Add wordCount filter
eleventyConfig.addFilter("wordCount", function (content) {
if (typeof content !== "string") {
return 0;
}
const words = content.split(/\s+/);
return words.length;
});
// CSS Minification
eleventyConfig.addFilter("cssmin", function (code) {
return new CleanCSS({}).minify(code).styles;
});
// Set custom directories for input, output, includes, and data
return {
// When a passthrough file is modified, rebuild the pages:
passthroughFileCopy: true,
dir: {
input: "src",
includes: "_includes",
layouts: "_layouts",
data: "_data",
output: "_site",
},
};
};