-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.eleventy.js
More file actions
96 lines (85 loc) · 2.9 KB
/
.eleventy.js
File metadata and controls
96 lines (85 loc) · 2.9 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
const { execSync } = require("child_process");
module.exports = function (eleventyConfig) {
// Pass-through copies (paths relative to project root for files outside src/)
eleventyConfig.addPassthroughCopy({ "images": "images" });
eleventyConfig.addPassthroughCopy({ "CNAME": "CNAME" });
eleventyConfig.addPassthroughCopy({ "favicon.ico": "favicon.ico" });
eleventyConfig.addPassthroughCopy({ "keybase.txt": "keybase.txt" });
// Build SCSS before Eleventy builds
eleventyConfig.on("eleventy.before", async () => {
execSync(
"npx sass src/css/main.scss:_site/css/main.css --style=compressed --load-path=src/css",
{ stdio: "inherit" }
);
});
// Nunjucks date filter (replaces Jekyll's date filters)
eleventyConfig.addFilter("dateDisplay", function (dateObj, format) {
const d = new Date(dateObj);
const months = [
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
];
if (format === "rfc822") {
return d.toUTCString();
}
if (format === "iso") {
return d.toISOString();
}
// Default: "Mon D, YYYY"
return `${months[d.getMonth()]} ${d.getDate()}, ${d.getFullYear()}`;
});
// Relative time filter ("2 days ago", "3 weeks ago", etc.)
eleventyConfig.addFilter("timeAgo", function (dateStr) {
if (!dateStr) return "";
const now = new Date();
const date = new Date(dateStr);
const seconds = Math.floor((now - date) / 1000);
if (seconds < 0) return "just now";
const intervals = [
{ label: "year", seconds: 31536000 },
{ label: "month", seconds: 2592000 },
{ label: "week", seconds: 604800 },
{ label: "day", seconds: 86400 },
{ label: "hour", seconds: 3600 },
{ label: "minute", seconds: 60 },
];
for (const interval of intervals) {
const count = Math.floor(seconds / interval.seconds);
if (count >= 1) {
return `${count} ${interval.label}${count > 1 ? "s" : ""} ago`;
}
}
return "just now";
});
// Truncate text to a max length with ellipsis
eleventyConfig.addFilter("truncate", function (str, len) {
if (!str) return "";
if (str.length <= len) return str;
return str.substring(0, len).trimEnd() + "…";
});
eleventyConfig.addFilter("xmlEscape", function (str) {
if (!str) return "";
return str
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
});
// Collections: blog posts
eleventyConfig.addCollection("posts", function (collectionApi) {
return collectionApi.getFilteredByGlob("src/posts/**/*.md").reverse();
});
return {
dir: {
input: "src",
output: "_site",
includes: "_includes",
layouts: "_layouts",
data: "_data",
},
templateFormats: ["njk", "md", "html"],
htmlTemplateEngine: "njk",
markdownTemplateEngine: "njk",
};
};