-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eleventy.js
83 lines (70 loc) · 2.39 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
75
76
77
78
79
80
81
82
83
const { DateTime } = require("luxon");
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const includesFilter = require("./blog/includes");
module.exports = (eleventyConfig) => {
eleventyConfig.addPassthroughCopy("blog/assets/images/");
eleventyConfig.addPassthroughCopy("blog/assets/css/themes/");
eleventyConfig.addPassthroughCopy("blog/assets/css/main.css");
eleventyConfig.addPassthroughCopy("blog/admin/");
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.addCollection("page", (collections) => {
return collections.getFilteredByTag("page").sort((a, b) => {
return a.data.order - b.data.order;
});
});
eleventyConfig.addShortcode(
"headers",
(title, subtitle) =>
`<h1 class="m-0 p-0 leading-none">${title}</h1>
<p class="">${subtitle}</p>`
);
eleventyConfig.addShortcode(
"currentDate",
() => {
return DateTime.utc().toISODate();
}
);
eleventyConfig.addFilter(
"postDate",
(date) => {
return DateTime.fromJSDate(date, { zone: 'utc' }).toLocaleString(DateTime.DATE_MED);
}
);
eleventyConfig.addFilter(
"sitemapDate",
(date) => {
var d = new Date();
var msSinceMidnight = date - d.setHours(0,0,0,0);
if (msSinceMidnight > 0) {
// console.log(date.toLocaleString()) // I give up
}
return DateTime.fromJSDate(date, { zone: 'utc' }).toISODate();
}
);
eleventyConfig.addFilter('imageUrl', (slug, filename) => {
return `/blog/assets/images/${slug}/${filename}`;
});
eleventyConfig.addFilter("urlPrefix", url => {
return url.startsWith('/blog/') ? url : `/blog/${url}`;
});
eleventyConfig.addCollection("sortedNavItems", function(collectionApi) {
return collectionApi.getFilteredByTag("navitem").sort(function(a, b) {
return a.data.o - b.data.o;
});
});
eleventyConfig.addFilter("sortByDate", (values) => {
let vals = [...values];
return vals.sort((a, b) => Math.sign(b.data.date - a.data.date));
});
eleventyConfig.addFilter('has_tag', includesFilter);
return {
dir: {
input: "blog",
data: "_data",
includes: "_includes",
layouts: "_layouts",
output: "_site_blog",
pathPrefix: "/blog/",
}
};
}