-
Notifications
You must be signed in to change notification settings - Fork 6
/
.eleventy.js
73 lines (60 loc) · 2.23 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
const { DateTime } = require("luxon");
const markdownIt = require('markdown-it');
const markdownItAnchor = require('markdown-it-anchor');
const string = require('string')
const slugify = s => string(s).slugify().toString()
const eleventyAsciidoc = require("eleventy-plugin-asciidoc");
const eleventyNavigationPlugin = require("@11ty/eleventy-navigation");
const pluginImages = require("./eleventy.config.images.js");
module.exports = function(eleventyConfig) {
eleventyConfig.addPassthroughCopy("static");
eleventyConfig.addPassthroughCopy("img");
eleventyConfig.addPassthroughCopy("js");
eleventyConfig.addPlugin(eleventyAsciidoc);
eleventyConfig.addPassthroughCopy("src/.well-known");
eleventyConfig.addPassthroughCopy("src/blog/**/*.png");
let markdownItOptions = {
html: true,
breaks: true,
linkify: true
};
// Watch content images for the image pipeline.
eleventyConfig.addWatchTarget("content/**/*.{svg,webp,png,jpeg}");
eleventyConfig.setLibrary(
'md',
markdownIt(markdownItOptions).use(markdownItAnchor, {
slugify: s => slugify(s),
permalink: markdownItAnchor.permalink.headerLink()
})
);
eleventyConfig.addPlugin(eleventyNavigationPlugin);
eleventyConfig.addPlugin(pluginImages);
eleventyConfig.addFilter("readableDate", (dateObj, format, zone) => {
// Formatting tokens for Luxon: https://moment.github.io/luxon/#/formatting?id=table-of-tokens
return DateTime.fromJSDate(dateObj, { zone: zone || "utc" }).toFormat(format || "dd LLLL yyyy");
});
eleventyConfig.addFilter('htmlDateString', (dateObj) => {
// dateObj input: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string
return DateTime.fromJSDate(dateObj, {zone: 'utc'}).toFormat('yyyy-LL-dd');
});
eleventyConfig.addFilter("groupByYear", (posts) => {
const groupedPosts = {};
posts.forEach(post => {
const year = DateTime.fromJSDate(post.date).year;
if (!groupedPosts[year]) {
groupedPosts[year] = [];
}
groupedPosts[year].push(post);
});
return Object.keys(groupedPosts).sort((a, b) => b - a).map(year => ({
year: year,
posts: groupedPosts[year]
}));
});
return {
dir: {
input: "src",
output: "_site"
}
}
};