-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.eleventy.js
More file actions
94 lines (86 loc) · 2.57 KB
/
.eleventy.js
File metadata and controls
94 lines (86 loc) · 2.57 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
module.exports = function(eleventyConfig) {
// Copy static files
eleventyConfig.addPassthroughCopy("src/images");
eleventyConfig.addPassthroughCopy("src/styles/output.css");
eleventyConfig.addPassthroughCopy("src/js");
// Add date filter
eleventyConfig.addFilter("readableDate", (dateObj) => {
return new Date(dateObj).toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
});
});
// Sort posts by date (newest first) and filter out future posts
eleventyConfig.addCollection("posts", function(collectionApi) {
const now = new Date();
return collectionApi.getFilteredByGlob("src/posts/*.md")
.filter(post => {
// Only include posts with dates on or before today
return post.date <= now;
})
.sort((a, b) => {
// Sort by date, newest first
return b.date - a.date;
});
});
// Collect all unique tags from posts
eleventyConfig.addCollection("tagList", function(collectionApi) {
const tagSet = new Set();
collectionApi.getAll().forEach(item => {
if ("tags" in item.data) {
let tags = item.data.tags;
// Handle both array and string tags
if (typeof tags === "string") {
tags = [tags];
}
for (const tag of tags) {
// Exclude special tags like "posts"
if (tag && tag !== "posts" && tag !== "all") {
tagSet.add(tag);
}
}
}
});
// Return sorted array of tags
return [...tagSet].sort();
});
// Collect tags with counts
eleventyConfig.addCollection("tagListWithCounts", function(collectionApi) {
const tagCount = {};
const posts = collectionApi.getFilteredByGlob("src/posts/*.md");
posts.forEach(post => {
if ("tags" in post.data) {
let tags = post.data.tags;
// Handle both array and string tags
if (typeof tags === "string") {
tags = [tags];
}
for (const tag of tags) {
// Exclude special tags like "posts"
if (tag && tag !== "posts" && tag !== "all") {
tagCount[tag] = (tagCount[tag] || 0) + 1;
}
}
}
});
// Return array of objects with tag and count
return Object.keys(tagCount)
.sort()
.map(tag => ({
tag: tag,
count: tagCount[tag]
}));
});
return {
dir: {
input: "src",
output: "_site",
includes: "_includes",
layouts: "_layouts"
},
templateFormats: ["md", "njk", "html"],
markdownTemplateEngine: "njk",
htmlTemplateEngine: "njk"
};
};