-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheleventy.config.js
More file actions
95 lines (81 loc) · 2.72 KB
/
eleventy.config.js
File metadata and controls
95 lines (81 loc) · 2.72 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
import syntaxHighlight from "@11ty/eleventy-plugin-syntaxhighlight";
import { feedPlugin } from "@11ty/eleventy-plugin-rss";
import { eleventyImageTransformPlugin } from "@11ty/eleventy-img";
import site from "./src/_data/site.js";
export default async function (eleventyConfig) {
eleventyConfig.setFrontMatterParsingOptions({
excerpt: true,
excerpt_separator: "---",
});
eleventyConfig.addTemplateFormats("xml");
eleventyConfig.addExtension("xml", {
key: "liquid", // Use the 'liquid' engine for .xml files
});
// Watch SASS files for changes
eleventyConfig.addWatchTarget("./src/scss/");
// Copy fonts
eleventyConfig.addPassthroughCopy("src/font");
// Copy images
eleventyConfig.addPassthroughCopy("src/img/assets");
eleventyConfig.addPassthroughCopy("src/favicon*");
// Syntax highlighting
eleventyConfig.addPlugin(syntaxHighlight);
// Add a group by year filter
eleventyConfig.addFilter("groupByYear", (collection) => {
const groupedObject = collection.reduce((acc, item) => {
const year = item.date.getFullYear();
if (!acc[year]) {
acc[year] = [];
}
acc[year].push(item);
return acc;
}, {});
// 2. Convert the object to an array of objects and sort by year descending (newest first)
const sortedArray = Object.entries(groupedObject)
// Sort by the year (key), descending (b[0] - a[0])
.toSorted((a, b) => b[0] - a[0])
// Map the result to a clean structure: [{ year: "2025", posts: [...] }, ...]
.map(([year, posts]) => ({
year: year,
posts: posts,
}));
// Return the simple, structured, pre-sorted array
return sortedArray;
});
// RSS
eleventyConfig.addPlugin(feedPlugin, {
type: "atom", // or "rss", "json"
outputPath: "/feed.xml",
collection: {
name: "post", // iterate over `collections.post`
limit: 10, // 0 means no limit
},
metadata: {
language: "en",
title: site.title,
subtitle: site.description,
base: site.url,
author: {
name: site.author.name,
},
},
});
eleventyConfig.addPlugin(eleventyImageTransformPlugin, {
widths: [800],
htmlOptions: {
imgAttributes: {
loading: "lazy",
decoding: "async",
},
fallback: "largest",
},
});
}
export const config = {
dir: {
input: "src",
includes: "_includes",
output: "_site",
data: "_data",
},
};