-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
63 lines (55 loc) · 1.66 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
const pluginRss = require("@11ty/eleventy-plugin-rss");
const markdownIt = require("markdown-it");
const fs = require("fs");
const { DateTime } = require("luxon");
module.exports = function (config) {
// Adding this just for the absoluteUrl filter used in 11ty examples
config.addPlugin(pluginRss);
// Support rendering data to markdown
let markdown = markdownIt({
html: true,
linkify: true,
});
config.addFilter("markdown", (value) => markdown.render(value));
// Formatting for dates
config.addFilter("readableDate", (dateStr) => {
return DateTime.fromISO(dateStr, { zone: "utc" }).toLocaleString(
DateTime.DATE_FULL
);
});
config.addFilter("htmlDateString", (dateObj) => {
return DateTime.fromJSDate(dateObj, { zone: "utc" }).toFormat("yyyy-LL-dd");
});
// Default href filter
config.addFilter("defaultHref", function (value, defaultHref) {
if (value === "#") {
return defaultHref;
} else {
return value;
}
});
// Pass through static assets
config.addPassthroughCopy("./src/site/images");
config.addPassthroughCopy("./src/site/fonts");
config.addPassthroughCopy("./src/site/_redirects");
config.addPassthroughCopy("./src/site/_headers");
// Browsersync to serve 404
config.setBrowserSyncConfig({
callbacks: {
ready: function (err, browserSync) {
const content_404 = fs.readFileSync("./dist/404.html");
browserSync.addMiddleware("*", (req, res) => {
res.write(content_404);
res.end();
});
},
},
});
return {
dir: {
input: "src/site",
output: "dist",
},
templateFormats: ["njk", "11ty.js", "md"],
};
};