generated from 5t3ph/11ty-netlify-jumpstart
-
Notifications
You must be signed in to change notification settings - Fork 226
/
.eleventy.js
102 lines (86 loc) · 2.73 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const emojiRegex = require("emoji-regex");
const slugify = require("slugify");
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const pluginRss = require("@11ty/eleventy-plugin-rss");
const markdownIt = require("markdown-it");
const markdownItAnchor = require("markdown-it-anchor");
const meta = require("./src/_data/meta");
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addWatchTarget("./src/sass/");
if (meta.environment !== "production") {
eleventyConfig.addPassthroughCopy("./src/styles");
}
eleventyConfig.addPassthroughCopy("./src/css");
eleventyConfig.addPassthroughCopy("./src/fonts");
eleventyConfig.addPassthroughCopy("./src/img");
eleventyConfig.addPassthroughCopy("./src/favicon.png");
eleventyConfig.addShortcode("year", () => `${new Date().getFullYear()}`);
eleventyConfig.addFilter("slug", (str) => {
if (!str) {
return;
}
const regex = emojiRegex();
// Remove Emoji first
let string = str.replace(regex, "");
return slugify(string, {
lower: true,
replacement: "-",
remove: /[*+~·,()'"`´%!?¿:@\/]/g,
});
});
eleventyConfig.addCollection("allPages", function (collection) {
return collection.getAll().filter((page) => {
return !page.data.style;
});
});
eleventyConfig.addCollection("allStyles", function (collection) {
return collection.getFilteredByTag("styles").sort((a, b) => {
return a.data.date < b.data.date ? -1 : a.data.date > b.data.date ? 1 : 0;
});
});
eleventyConfig.addCollection("featureStyles", function (collection) {
return collection
.getFilteredByTag("styles")
.sort(() => {
return 0.5 - Math.random();
})
.slice(0, 3);
});
eleventyConfig.addFilter("jsonTitle", (str) => {
if (!str) {
return;
}
let title = str.replace(/((.*)\s(.*)\s(.*))$/g, "$2 $3 $4");
title = title.replace(/"(.*)"/g, '\\"$1\\"');
return title;
});
eleventyConfig.addFilter("limit", function (arr, limit) {
return arr.slice(0, limit);
});
eleventyConfig.addFilter("createList", function (arr, selections) {
return arr.filter((item) => selections.includes(item.title));
});
/* Markdown Overrides */
let markdownLibrary = markdownIt({
html: true,
}).use(markdownItAnchor, {
permalink: false,
level: [1, 2, 3],
slugify: (s) =>
s
.trim()
.toLowerCase()
.replace(/[\s+~\/]/g, "-")
.replace(/[().`,%·'"!?¿:@*]/g, ""),
});
eleventyConfig.setLibrary("md", markdownLibrary);
return {
passthroughFileCopy: true,
dir: {
input: "src",
output: "public",
},
};
};