-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.eleventy.js
More file actions
85 lines (70 loc) · 2.06 KB
/
Copy path.eleventy.js
File metadata and controls
85 lines (70 loc) · 2.06 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
function slugifyTag(value) {
return String(value || "")
.trim()
.toLowerCase()
.replace(/[^a-z0-9]+/g, "-")
.replace(/^-+|-+$/g, "");
}
module.exports = function (eleventyConfig) {
eleventyConfig.addPassthroughCopy({ "blog/assets": "assets" });
eleventyConfig.addCollection("publishedPosts", function (collectionApi) {
return collectionApi
.getFilteredByGlob("blog/posts/*.md")
.filter((item) => item.data.status === "published")
.sort((a, b) => b.date - a.date);
});
eleventyConfig.addCollection("tagGroups", function (collectionApi) {
const posts = collectionApi
.getFilteredByGlob("blog/posts/*.md")
.filter((item) => item.data.status === "published")
.sort((a, b) => b.date - a.date);
const tagsByKey = new Map();
for (const post of posts) {
for (const tag of post.data.tags || []) {
const label = String(tag || "").trim();
if (!label) {
continue;
}
const key = label.toLowerCase();
if (!tagsByKey.has(key)) {
tagsByKey.set(key, {
tag: label,
slug: slugifyTag(label),
posts: []
});
}
tagsByKey.get(key).posts.push(post);
}
}
return Array.from(tagsByKey.values()).sort((a, b) =>
a.tag.localeCompare(b.tag, "en", { sensitivity: "base" })
);
});
eleventyConfig.addCollection("sitePages", function (collectionApi) {
return collectionApi.getFilteredByGlob("blog/pages/*.md");
});
eleventyConfig.addFilter("readableDate", function (value) {
if (!value) {
return "";
}
return new Date(value).toLocaleDateString("en-US", {
year: "numeric",
month: "long",
day: "numeric",
timeZone: "UTC"
});
});
eleventyConfig.addFilter("tagUrl", function (value) {
return "/tags/" + slugifyTag(value) + "/";
});
return {
dir: {
input: "blog",
includes: "_includes",
output: "_site"
},
markdownTemplateEngine: "njk",
htmlTemplateEngine: "njk",
dataTemplateEngine: "njk"
};
};