-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eleventy.js
52 lines (44 loc) · 1.25 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
import { DateTime } from "luxon";
import pluginRss from "@11ty/eleventy-plugin-rss";
/**
* Copy static files like images, styles and scripts.
*/
function copyStaticFiles(eleventyConfig) {
const staticResources = ["src/assets", "src/style.css", "src/_routes.json"];
staticResources.forEach((resource) =>
eleventyConfig.addPassthroughCopy(resource),
);
}
/**
* Add filter to format dates.
*/
function addDateFormatFilter(eleventyConfig) {
eleventyConfig.addFilter("postDate", (dateObj) =>
DateTime.fromJSDate(dateObj).toLocaleString(DateTime.DATE_FULL),
);
// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string
eleventyConfig.addFilter("htmlDateString", (dateObj) =>
DateTime.fromJSDate(dateObj).toFormat("yyyy-LL-dd"),
);
}
/**
* Pick random item from collection.
*/
function addRandomItemFilter(eleventyConfig) {
eleventyConfig.addFilter(
"random",
(items) => items[Math.floor(Math.random() * items.length)],
);
}
export default function (eleventyConfig) {
copyStaticFiles(eleventyConfig);
addDateFormatFilter(eleventyConfig);
addRandomItemFilter(eleventyConfig);
eleventyConfig.addPlugin(pluginRss);
return {
htmlTemplateEngine: "njk",
dir: {
input: "src",
},
};
}