-
Notifications
You must be signed in to change notification settings - Fork 2
/
.eleventy.js
74 lines (64 loc) · 1.97 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
import fs from "fs";
import pluginRss from "@11ty/eleventy-plugin-rss";
import syntaxHighlight from "@11ty/eleventy-plugin-syntaxhighlight";
export default function (eleventyConfig) {
const passthroughDirs = ["src/img", "src/css", "src/fonts"];
passthroughDirs.forEach((dir) => eleventyConfig.addPassthroughCopy(dir));
const getSvgContent = function (file) {
let relativeFilePath = `./src/img/${file}.svg`;
let data = fs.readFileSync(relativeFilePath, function (err, contents) {
if (err) return err;
return contents;
});
return data.toString("utf8");
};
eleventyConfig.addShortcode("svg", getSvgContent);
eleventyConfig.addShortcode("year", () => `${new Date().getFullYear()}`);
function formatDateHuman(date) {
if (!date) return "";
if (typeof date === "string") return formatDateHuman(new Date(date));
const monthNames = [
"januar",
"februar",
"mars",
"april",
"mai",
"juni",
"juli",
"august",
"september",
"oktober",
"november",
"desember",
];
return `${date.getDate()}. ${
monthNames[date.getMonth()]
} ${date.getFullYear()}`;
}
eleventyConfig.addFilter("formatDateISO", (date) =>
date ? date.toISOString().substring(0, 10) : "",
);
eleventyConfig.addFilter("formatDateHuman", formatDateHuman);
const now = new Date();
eleventyConfig.addFilter("futureEvents", (events) =>
events.filter(
(event) => new Date(event.dateEnd).getTime() >= now.getTime(),
),
);
eleventyConfig.addFilter("pastEvents", (events) =>
events.filter((event) => new Date(event.dateEnd).getTime() < now.getTime()),
);
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPlugin(syntaxHighlight);
return {
dir: {
input: "src",
output: "_site",
data: "_data",
},
templateFormats: ["html", "njk", "md", "11ty.js"],
markdownTemplateEngine: "njk",
htmlTemplateEngine: "njk",
passthroughFileCopy: true,
};
}