-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy patheleventy.config.js
More file actions
132 lines (111 loc) · 4.04 KB
/
eleventy.config.js
File metadata and controls
132 lines (111 loc) · 4.04 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
const markdownIt = require('markdown-it');
const Terser = require("terser");
const through = require('through2');
module.exports = eleventyConfig => {
process.env.TZ = 'UTC';
// Turn off extensionless layouts
// https://www.11ty.dev/docs/layouts/#omitting-the-layouts-file-extension
eleventyConfig.setLayoutResolution(false);
eleventyConfig.addPlugin(require("@11ty/eleventy-plugin-syntaxhighlight"));
eleventyConfig.addPassthroughCopy('./docs/asf.md');
eleventyConfig.addPassthroughCopy('./docs/static');
// Copy and minify src/code.js to _site/static/js
eleventyConfig.addPassthroughCopy(
{
"./docs/src/code.js": "static/js/code.min.js",
},
{
transform: function () {
let buffer = '';
return through(
function (chunk, enc, done) {
buffer += chunk.toString();
done();
},
function (done) {
// INFO: this usage is very specific to the pinned Terser 4.8.0,
// if Terser is ever updated, this will break.
const result = Terser.minify(buffer);
if (result.error) {
console.log('Error minifying code.js:', result.error);
}
done(null, result.code);
}
);
}
}
);
eleventyConfig.setLiquidOptions({
jekyllInclude: true,
});
// use e.g. /learn.html in preference to /learn/
eleventyConfig.addGlobalData('permalink', '/{{ page.filePathStem }}.html');
eleventyConfig.addCollection('guides', collectionApi => {
return collectionApi.getFilteredByTag('guides').sort((a, b) => a.data.index - b.data.index);
});
eleventyConfig.addCollection('pages', collectionApi => {
// zero-indexed, but skip page 1, as it's served at /blog/
const pageCount = Math.ceil(collectionApi.getFilteredByTag('posts').length / 5) - 1;
const blogPages = Array.from(
{ length:pageCount },
(_, n) => ({
url: `/blog/page${n+2}/`,
}),
);
return [
...collectionApi.getAll().filter(item => !item.data.tags),
...blogPages,
];
});
eleventyConfig.addCollection('posts', collectionApi => {
return collectionApi
.getFilteredByTag('posts')
.sort((a, b) => b.date - a.date || b.inputPath.localeCompare(a.inputPath));
});
eleventyConfig.addFilter('first_paragraph', function (content) {
const marker = '</p>';
const idx = content.indexOf(marker);
if (idx === -1) {return content;}
return content.substring(0, idx + marker.length);
});
eleventyConfig.addFilter('liquid', function (content) {
if (!this.liquid) {return content;}
return this.liquid.parseAndRender(content, this.context);
});
const md = markdownIt({
html: true,
});
eleventyConfig.addFilter('inlinemarkdown', content => md.renderInline(content));
// Re-defined markdown-it lib to prevent eleventy messing with internals.
// See: https://github.com/11ty/eleventy/issues/2438
eleventyConfig.setLibrary('md', md);
eleventyConfig.addFilter('markdown', content => md.render(content));
eleventyConfig.addPairedShortcode('markdown', content => md.render(content));
function pubDateRFC822(value, timeZone = undefined) {
const date = new Date(value);
const options = {
weekday: 'short',
day: '2-digit',
month: 'short',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hourCycle: 'h23',
timeZone: timeZone,
timeZoneName: 'longOffset',
};
const formattedDate = new Intl.DateTimeFormat('en-US', options).format(date);
const [wkd, mmm, dd, yyyy, time, z] = formattedDate.replace(/([,\s]+)/g, ' ').split(' ');
// This is valid regex, even if ESLint complains. It’s also not ignorable for some reason.
const tz = z.replace(/GMT(?<sign>\+|\-)(?<hour>\d\d):(?<minute>\d\d)/, '$<sign>$<hour>$<minute>');
return `${wkd}, ${dd} ${mmm} ${yyyy} ${time} ${tz}`;
}
eleventyConfig.addLiquidFilter("dateToRfc882", pubDateRFC822);
return {
dir: {
input: './docs',
output: "docs/_site"
},
};
};