-
Notifications
You must be signed in to change notification settings - Fork 11
/
.eleventy.js
executable file
·199 lines (178 loc) · 6.27 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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
const MarkdownIt = require("markdown-it");
const MarkdownItAnchor = require("markdown-it-anchor");
const MarkdownItTOC = require("markdown-it-toc-done-right");
const EleventyNavigation = require("@11ty/eleventy-navigation");
const EleventySyntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const { DateTime } = require("luxon");
const { EleventyHtmlBasePlugin } = require("@11ty/eleventy");
const PosixPath = require("node:path").posix;
class DefaultDict {
constructor(defaultValue) {
return new Proxy({}, {
get: (target, name) => name in target ? target[name] : defaultValue
});
}
}
const pluginRss = require("@11ty/eleventy-plugin-rss");
const endSlashRe = /\/$/;
function findSitemapEntries(collection, curPath = "/") {
if (curPath !== "/" && curPath.match(endSlashRe))
curPath = curPath.replace(endSlashRe, "");
let pages = [];
for (let item of collection) {
if (item.data && !item.data.skipHtmlSitemap && item.data.title) {
const itemPath = (new URL(item.url, "http://example.com")).pathname;
const itemParent = item.data.htmlSitemapParent || PosixPath.dirname(itemPath);
if (curPath == itemParent) {
pages.push({
key: itemPath,
url: item.url,
title: item.data.htmlSitemapTitle || item.data.title,
order: item.data.htmlSitemapOrder || 0,
parent: itemParent,
children: (curPath === itemPath) ? [] : findSitemapEntries(collection, itemPath),
pluginType: "eleventy-navigation",
})
}
}
}
return pages.sort((a, b) => (a.order || 0) - (b.order || 0));
}
module.exports = function(eleventyConfig) {
eleventyConfig.addPassthroughCopy('css')
eleventyConfig.addPassthroughCopy('js')
eleventyConfig.addPassthroughCopy('vendor')
eleventyConfig.addPassthroughCopy('assets')
eleventyConfig.addPassthroughCopy('release/verify/*.key')
eleventyConfig.addPlugin(EleventyHtmlBasePlugin);
eleventyConfig.addPlugin(EleventyNavigation);
eleventyConfig.addPlugin(EleventySyntaxHighlight);
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.setLiquidOptions({
dynamicPartials: false,
strictFilters: false, // renamed from `strict_filters` in Eleventy 1.0
});
eleventyConfig.addFilter("postDate", (dateObj) => {
return DateTime.fromJSDate(dateObj).toLocaleString(DateTime.DATE_MED);
});
eleventyConfig.addFilter("dateString", (value) => {
return new Date(value).toDateString();
});
eleventyConfig.addFilter("isodate", (value) => {
return new Date(value).toISOString();
});
eleventyConfig.addFilter("arrayLength", (value) => {
return value.length;
});
eleventyConfig.addFilter('topLevel', (path) => {
if (path == "/") return "/";
return path.match(/^(.+?\/)/)[1];
});
eleventyConfig.addFilter("htmlSitemap", findSitemapEntries);
eleventyConfig.addShortcode("currentYear", () => `${new Date().getFullYear()}`);
eleventyConfig.addCollection("recentPosts", (collectionApi) => {
let i =0;
return collectionApi.getFilteredByGlob(["security/*.md", "release/*.md", "blog/*.md"]).reverse().filter((item) => {
return i++ < 10;
});
})
eleventyConfig.addCollection("recentBlogPosts", (collectionApi) => {
let i =0;
return collectionApi.getFilteredByTag("blogpost").reverse().filter((item) => {
return i++ < 6;
});
})
eleventyConfig.addCollection("recentReleaseNotes", (collectionApi) => {
let i =0;
return collectionApi.getFilteredByTag("release").reverse().filter((item) => {
return i++ < 5;
});
})
eleventyConfig.addCollection("pkgCatalog", collection => {
let pkgCatalog = new Object;
collection.getAll().forEach(item => {
let thisPkg = item.data.package;
if (!thisPkg) return;
if (!pkgCatalog[thisPkg]) pkgCatalog[thisPkg] = {
latestStable: new Object,
latestDev: new Object,
recent: new Array,
list: new Array, // rename "list"?
};
let itemType = (item.data.tags).filter(value => /stable$/.test(value)).toString();
let thisData = {
version: item.data.version,
date: item.date,
url: item.url,
type: itemType,
};
pkgCatalog[thisPkg].list.push(thisData);
});
for (const pkg in pkgCatalog) {
let thisPkg = pkgCatalog[pkg];
//https://www.javascripttutorial.net/array/javascript-sort-an-array-of-objects/
thisPkg.list.sort((a,b) => {
return b.date - a.date - 0.1;
});
let stableVer = thisPkg.list.findIndex(x => x.type === "stable");
let developVer = thisPkg.list.findIndex(x => x.type === "unstable");
thisPkg.latestStable = {...thisPkg.list[stableVer]};
thisPkg.latestDev = {...thisPkg.list[developVer]};
//https://stackoverflow.com/a/35398031 (finding by object in array)
thisPkg.recent = thisPkg.list.splice(0,5);
};
return pkgCatalog;
});
eleventyConfig.addCollection("latestReleases", (collectionApi) => {
const makeFilter = function () {
let seenPackages = new DefaultDict(false);
return (item) => {
const package = item.data.package;
if (seenPackages[package])
return false;
seenPackages[package] = true;
return true;
};
};
const gatherLatest = function (result, kind) {
for (let item of collectionApi.getFilteredByTags("release", kind).reverse().filter(makeFilter())) {
const package = item.data.package;
if (package === undefined)
continue;
if (result[package] === undefined)
result[package] = {};
result[package][kind] = {
version: item.data.version,
date: item.date,
package: package,
kind: kind,
url: item.url,
};
}
};
let result = {};
gatherLatest(result, "stable");
gatherLatest(result, "unstable");
return result;
});
eleventyConfig.addCollection("recentWSA", (collectionApi) => {
let i =0;
return collectionApi.getFilteredByTag("WSA").reverse().filter((item) => {
return i++ < 5;
});
})
eleventyConfig.setLibrary("md", MarkdownIt({
typographer: true,
linkify: false,
breaks: false,
html: true,
}).use(MarkdownItAnchor, {
level: 2,
}).use(MarkdownItTOC, {
level: [2, 3],
})
);
return {
passthroughFileCopy: true,
}
}