-
Notifications
You must be signed in to change notification settings - Fork 1
/
.eleventy.js
83 lines (74 loc) · 2.36 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
const yaml = require('js-yaml');
const markdownIt = require("markdown-it");
const eleventyNavigationPlugin = require("@11ty/eleventy-navigation");
const pluginRss = require('@11ty/eleventy-plugin-rss');
const md = require('markdown-it')({
html: false,
breaks: true,
linkify: true,
});
const hashCode = function (s) {
var hash = 0,
i,
chr;
if (s.length === 0) return hash;
for (i = 0; i < s.length; i++) {
chr = s.charCodeAt(i);
hash = (hash << 5) - hash + chr;
hash |= 0;
}
return (hash >>> 0).toString(16);
};
module.exports = function (eleventyConfig) {
eleventyConfig.addDataExtension("yaml", (contents) => yaml.load(contents));
eleventyConfig.addPassthroughCopy("assets");
eleventyConfig.addPassthroughCopy("favicon.ico");
eleventyConfig.addPassthroughCopy("robots.txt");
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPlugin(eleventyNavigationPlugin);
eleventyConfig.addFilter("hashcode", (s) => hashCode(s));
eleventyConfig.addFilter("markdown", (markdownString) =>
md.render(markdownString)
);
// Take Eleventy's default "YY-MM-DD" to "Month DD, YYYY"
// Usage: {{ dateString | friendlydate }}
eleventyConfig.addFilter("friendlydate", (dateString) =>
new Date(dateString).toLocaleDateString("en-us", {
month: "long",
day: "numeric",
year: "numeric",
})
);
// Limit a collection to the first N items
// Usage: {{ collection | limit(N) }}
eleventyConfig.addFilter("limit", function (array, limit) {
return array.slice(0, limit);
});
// Remove the first character from a string
// Usage: {{ string | remove_leading_char }}
// Ex. "/href/" -> "href/"
eleventyConfig.addFilter("remove_leading_char", function (contents) {
return contents.slice(1, contents.length);
});
// Sort an array by path name. Used to ensure collections are sorted by 01, 02, ... Rather than by creation date.
eleventyConfig.addFilter("sortAscendingByName", function (array) {
return array.sort(function (a, b) {
return a.inputPath.localeCompare(b.inputPath);
});
});
const md = new markdownIt({
html: true,
});
eleventyConfig.addPairedShortcode("markdown", (content) => {
return md.render(content);
});
return {
markdownTemplateEngine: "njk",
dir: {
input: "src",
includes: "_includes",
data: "_data",
output: "_site",
},
};
};