generated from 5t3ph/11ty-netlify-jumpstart
-
Notifications
You must be signed in to change notification settings - Fork 1
/
.eleventy.js
116 lines (101 loc) · 3.98 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
const socialImages = require("@11tyrocks/eleventy-plugin-social-images");
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 packageVersion = require("./package.json").version;
let ytEmbed = /https?:\/\/www\.youtube\.com\/embed\/([\w-]{11})/i
let ytNoCookieEmbed = /https?:\/\/www\.youtube\-nocookie\.com\/embed\/([\w-]{11})/i
let ytWatch = /https?:\/\/www\.youtube\.com\/watch\?vi?=([\w-]{11})/i
let ytShort = /https?:\/\/youtu\.be\/([\w-]{11})/i
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(socialImages);
eleventyConfig.addPlugin(syntaxHighlight);
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addWatchTarget("./src/sass/");
eleventyConfig.addPassthroughCopy("./src/css");
eleventyConfig.addPassthroughCopy("./src/fonts");
eleventyConfig.addPassthroughCopy("./src/img");
eleventyConfig.addPassthroughCopy("./src/favicon.png");
eleventyConfig.addShortcode("year", () => `${new Date().getFullYear()}`);
eleventyConfig.addShortcode("packageVersion", () => `v${packageVersion}`);
// Make it easier to remember layout names
['base', 'event', 'page'].forEach(layout => {
eleventyConfig.addLayoutAlias(layout, `layouts/${layout}.njk`);
});
// Turn a date into "MM-YYYY"
eleventyConfig.addFilter("mmyyyy", (date) => {
let [month, day, year] = new Date(date).toLocaleDateString("en-US").split("/");
return `${("0"+month).substr(-2)}/${year}`;
});
// Get items from an array starting at an offset
eleventyConfig.addFilter("from", (array, from) => {
return array.slice(from, array.length);
});
// Check if a date has occurred
eleventyConfig.addFilter("occurred", (date) => {
let dateToCheck = new Date(date);
let today = new Date();
return dateToCheck < today;
});
// Filter to format the date in the same way we're doing it clientside, to be used in places
eleventyConfig.addFilter("formatTheDate", (date) => {
return new Intl.DateTimeFormat('default', {
month: 'long',
day: 'numeric',
hour: 'numeric',
hour12: true,
timeZoneName: 'short'
})
.format(new Date(date))
})
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,
});
});
// Turn any kind of youtube sharing link into a video wrapped iframe embed link pointing at
// the nocookie version.
eleventyConfig.addShortcode("yt", (str) => {
let id = ""
if ((match = str.match(ytNoCookieEmbed)) !== null) {
// is it a nocookie youtube embed link? like https://www.youtube-nocookie.com/embed/ps_UUldWqHY
id = match[1];
} else if ((match = str.match(ytEmbed)) !== null) {
// is this an embed link without the nocookie part? like https://www.youtube.com/embed/ps_UUldWqHY
id = match[1];
} else if ((match = str.match(ytWatch)) !== null) {
// is it a youtube watch link? like https://www.youtube.com/?v=ps_UUldWqHY
id = match[1];
} else if ((match = str.match(ytShort)) !== null) {
// is it a short youtube link? like https://youtu.be/ps_UUldWqHY
id = match[1];
} else {
return "";
}
return `<div class="videoWrapper">
<iframe width="1120" height="630" src="https://www.youtube-nocookie.com/embed/${id}" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>`
});
/* Markdown Overrides */
let markdownLibrary = markdownIt({
html: true,
});
eleventyConfig.setLibrary("md", markdownLibrary);
return {
passthroughFileCopy: true,
dir: {
input: "src",
output: "public",
},
};
};