generated from 5t3ph/11ty-sass-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path.eleventy.js
57 lines (45 loc) · 1.58 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
const { DateTime } = require("luxon");
const slugify = require("slugify");
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.addWatchTarget("./src/sass/");
eleventyConfig.addFilter("slug", (str) => {
return slugify(str, {
lower: true,
strict: true,
remove: /["]/g,
});
});
eleventyConfig.addFilter("postDate", (dateObj) => {
return DateTime.fromJSDate(dateObj).toLocaleString(DateTime.DATE_MED);
});
eleventyConfig.addShortcode("newCount", (items, source, slug) => {
const newItems = items.filter((i) => {
return i.data.source === source && i.data.new === "true";
});
return newItems.length > 0
? `<span class="new-count background-primary" aria-describedby="${slug}">${newItems.length}<span class="inclusively-hidden"> new items</span></span>`
: "";
});
eleventyConfig.addFilter("limit", function (arr, limit) {
return arr.slice(0, limit);
});
eleventyConfig.addFilter("domain", function (url) {
const domain = new URL(url);
return domain.hostname.replace("www.", "");
});
eleventyConfig.addFilter("dateLimitDisplay", (dateObj) => {
return DateTime.fromMillis(dateObj).toLocaleString(DateTime.DATE_MED);
});
eleventyConfig.addFilter("stripUnsafe", (content) => {
const regex = /<script(.+?)<\/script>/gim;
return content != undefined ? content.replace(regex, " ") : content;
});
return {
dir: {
input: "src",
output: "public",
},
};
};