-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.eleventy.js
More file actions
151 lines (128 loc) · 5.16 KB
/
.eleventy.js
File metadata and controls
151 lines (128 loc) · 5.16 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
const yaml = require("js-yaml");
const { DateTime } = require("luxon");
const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const htmlmin = require("html-minifier");
const Image = require("@11ty/eleventy-img");
// Image shortcode for responsive images
async function imageShortcode(src, alt, sizes = "100vw") {
if (!src) {
throw new Error(`Missing image path: ${src}`);
}
let metadata = await Image(src, {
widths: [300, 600, 900, 1200],
formats: ["webp", "jpeg"],
urlPath: "/static/img/",
outputDir: "./_site/static/img/",
filenameFormat: function (id, src, width, format) {
const extension = format;
const name = src.split("/").pop().split(".")[0];
return `${name}-${width}w.${extension}`;
}
});
let imageAttributes = {
alt,
sizes,
loading: "lazy",
decoding: "async",
};
return Image.generateHTML(metadata, imageAttributes);
}
module.exports = function (eleventyConfig) {
// Disable automatic use of your .gitignore
eleventyConfig.setUseGitIgnore(false);
// Merge data instead of overriding
eleventyConfig.setDataDeepMerge(true);
// Add image shortcode
eleventyConfig.addNunjucksAsyncShortcode("image", imageShortcode);
eleventyConfig.addJavaScriptFunction("image", imageShortcode);
// human readable date
eleventyConfig.addFilter("readableDate", (dateObj) => {
return DateTime.fromJSDate(dateObj, { zone: "utc" }).toFormat(
"dd LLL yyyy"
);
});
// Date formatting (machine readable)
eleventyConfig.addFilter("machineDate", (dateObj) => {
return DateTime.fromJSDate(dateObj, { zone: "utc" }).toFormat("yyyy-MM-dd");
});
// Array slice filter for collections
eleventyConfig.addFilter("slice", (array, start, end) => {
return array.slice(start, end);
});
// HTML escape filter for data attributes
eleventyConfig.addFilter("htmlescape", (content) => {
return content
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''')
.replace(/\n/g, ' ')
.replace(/\r/g, '');
});
// Syntax Highlighting for Code blocks
eleventyConfig.addPlugin(syntaxHighlight);
// To Support .yaml Extension in _data
// You may remove this if you can use JSON
eleventyConfig.addDataExtension("yaml", (contents) => yaml.load(contents));
// Add collections
eleventyConfig.addCollection("pages", function(collection) {
return collection.getFilteredByGlob("src/_pages/*.md");
});
eleventyConfig.addCollection("robots", function(collection) {
return collection.getFilteredByGlob("src/_robots/*.md").sort((a, b) => b.data.year - a.data.year);
});
eleventyConfig.addCollection("sponsors", function(collection) {
return collection.getFilteredByGlob("src/_sponsors/*.md");
});
// Copy Static Files to /_Site
eleventyConfig.addPassthroughCopy({
"./src/admin/config.yml": "./admin/config.yml",
"./node_modules/alpinejs/dist/cdn.min.js": "./static/js/alpine.js",
"./node_modules/prismjs/themes/prism-tomorrow.css":
"./static/css/prism-tomorrow.css",
"./node_modules/@phosphor-icons/web/src/regular/style.css": "./static/css/phosphor-regular.css",
"./node_modules/@phosphor-icons/web/src/fill/style.css": "./static/css/phosphor-fill.css",
// Copy Phosphor font files
"./node_modules/@phosphor-icons/web/src/regular/Phosphor.woff2": "./static/css/Phosphor.woff2",
"./node_modules/@phosphor-icons/web/src/regular/Phosphor.woff": "./static/css/Phosphor.woff",
"./node_modules/@phosphor-icons/web/src/regular/Phosphor.ttf": "./static/css/Phosphor.ttf",
"./node_modules/@phosphor-icons/web/src/fill/Phosphor-Fill.woff2": "./static/css/Phosphor-Fill.woff2",
"./node_modules/@phosphor-icons/web/src/fill/Phosphor-Fill.woff": "./static/css/Phosphor-Fill.woff",
"./node_modules/@phosphor-icons/web/src/fill/Phosphor-Fill.ttf": "./static/css/Phosphor-Fill.ttf",
});
// Copy Image Folder to /_site
eleventyConfig.addPassthroughCopy("./src/static/img");
eleventyConfig.addPassthroughCopy("./src/static/sponsorship-prospectus.pdf");
// Copy favicon to route of /_site
eleventyConfig.addPassthroughCopy("./src/favicon.ico");
// Minify HTML
eleventyConfig.addTransform("htmlmin", function (content, outputPath) {
// Eleventy 1.0+: use this.inputPath and this.outputPath instead
if (outputPath && outputPath.endsWith(".html")) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true,
});
return minified;
}
return content;
});
eleventyConfig.addShortcode("youtube", function(id, title = "YouTube video") {
return `<div class="responsive-iframe">
<iframe width="560" height="315" src="https://www.youtube.com/embed/${id}"
title="${title}" frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen></iframe>
</div>`;
});
// Let Eleventy transform HTML files as nunjucks
// So that we can use .html instead of .njk
return {
dir: {
input: "src",
},
htmlTemplateEngine: "njk",
};
};