-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.eleventy.js
231 lines (184 loc) · 6.96 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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
const CleanCSS = require("clean-css");
const pluginRss = require("@11ty/eleventy-plugin-rss");
const moment = require("moment");
const htmlmin = require("html-minifier");
//onst { refreshAccessToken, fetchStravaActivities } = require('./strava');
const eleventyImagePlugin = require("@11ty/eleventy-img");
module.exports = function(eleventyConfig) {
eleventyConfig.addTransform("htmlmin", function(content) {
// Prior to Eleventy 2.0: use this.outputPath instead
if( this.page.outputPath && this.page.outputPath.endsWith(".html") ) {
let minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true
});
return minified;
}
return content;
});
// clean css
eleventyConfig.addFilter("cssmin", function(code) {
return new CleanCSS({}).minify(code).styles;
});
// rss filter
eleventyConfig.addPlugin(pluginRss);
// duration filter
eleventyConfig.addNunjucksFilter("duration", function (duration, format) {
return moment('1900-01-01 00:00:00').seconds(duration).format(format);
});
// date filter
eleventyConfig.addNunjucksFilter("date", function (date, format) {
return moment(date).format(format);
});
// miles filter
eleventyConfig.addNunjucksFilter("miles", function (miles) {
return parseFloat(miles/1609.344).toFixed(2);
});
// two decimal places filter
eleventyConfig.addNunjucksFilter("decimal", function (decimal) {
return parseFloat(decimal).toFixed(2);
});
// two decimal places filter
eleventyConfig.addNunjucksFilter("divide100", function (divide100) {
return parseFloat(divide100/100).toFixed(2);
});
// meters/second to mph
eleventyConfig.addNunjucksFilter("mph", function (mph) {
return parseFloat(mph*2.2369369).toFixed(2);
});
eleventyConfig.addPassthroughCopy("android-chrome-*.png");
eleventyConfig.addPassthroughCopy("apple-touch-icon.png");
eleventyConfig.addPassthroughCopy("favicon.ico");
eleventyConfig.addPassthroughCopy("favicon-*.png");
eleventyConfig.addPassthroughCopy("site.webmanifest");
eleventyConfig.addPassthroughCopy("google88f9e8b0497a35bd.html");
eleventyConfig.addPassthroughCopy("*.txt");
eleventyConfig.addPassthroughCopy("*.xsl");
eleventyConfig.addPassthroughCopy("fonts/");
// minify js
const { minify } = require("terser");
eleventyConfig.addNunjucksAsyncFilter("jsmin", async function (
code,
callback
) {
try {
const minified = await minify(code);
callback(null, minified.code);
} catch (err) {
console.error("Terser error: ", err);
// Fail gracefully.
callback(null, code);
}
});
eleventyConfig.addShortcode("storyImage", async function(src, alt) {
let metadata = await eleventyImagePlugin(src, {
widths: [480, 768],
formats: ["avif", "jpeg"],
outputDir: "./_site/img/",
sharpAvifOptions: {
quality: 85
},
//useCache: false
});
let imageAttributes = {
alt,
sizes: "(min-width: 30em) 50vw, 100vw",
loading: "lazy",
decoding: "async",
};
return eleventyImagePlugin.generateHTML(metadata, imageAttributes);
});
eleventyConfig.addShortcode("gridImage", async function(src, alt) {
let metadata = await eleventyImagePlugin(src, {
widths: [480],
formats: ["avif", "jpeg"],
outputDir: "./_site/img/",
sharpAvifOptions: {
quality: 65
}
});
let imageAttributes = {
alt,
//sizes: "(min-width: 30em) 50vw, 100vw",
loading: "lazy",
decoding: "async",
};
return eleventyImagePlugin.generateHTML(metadata, imageAttributes);
});
eleventyConfig.addShortcode("storyImageAnimated", async function(src, alt) {
let metadata = await eleventyImagePlugin(src, {
widths: [480],
outputDir: "./_site/img/",
formats: ["webp", "gif"],
sharpOptions: {
animated: true,
},
});
let imageAttributes = {
alt,
sizes: "(min-width: 30em) 50vw, 100vw",
loading: "lazy",
decoding: "async",
};
return eleventyImagePlugin.generateHTML(metadata, imageAttributes);
});
// Combine running.activityList and running2023.activityList
eleventyConfig.addCollection("combinedActivityList", function(_) {
const runningActivities = require("./_data/running.json");
const running2020Activities = require("./_data/running2020.json");
const running2021Activities = require("./_data/running2021.json");
const running2022Activities = require("./_data/running2022.json");
const running2023Activities = require("./_data/running2023.json");
const running2024Activities = require("./_data/running2024.json");
const combinedActivities = runningActivities.activityList.concat(running2024Activities.activityList).concat(running2023Activities.activityList).concat(running2022Activities.activityList).concat(running2021Activities.activityList).concat(running2020Activities.activityList);
const filteredActivities = combinedActivities.filter(item => item.sportTypeId == "1");
return filteredActivities;
});
eleventyConfig.addCollection("2024ActivityList", function(_) {
const runningActivities = require("./_data/running2024.json");
const filteredActivities = runningActivities.activityList.filter(item => item.sportTypeId == "1");
return filteredActivities;
});
eleventyConfig.addCollection("2023ActivityList", function(_) {
const runningActivities = require("./_data/running2023.json");
const filteredActivities = runningActivities.activityList.filter(item => item.sportTypeId == "1");
return filteredActivities;
});
eleventyConfig.addCollection("2022ActivityList", function(_) {
const runningActivities = require("./_data/running2022.json");
const filteredActivities = runningActivities.activityList.filter(item => item.sportTypeId == "1");
return filteredActivities;
});
eleventyConfig.addCollection("2021ActivityList", function(_) {
const runningActivities = require("./_data/running2021.json");
const filteredActivities = runningActivities.activityList.filter(item => item.sportTypeId == "1");
return filteredActivities;
});
eleventyConfig.addCollection("2020ActivityList", function(_) {
const runningActivities = require("./_data/running2020.json");
const filteredActivities = runningActivities.activityList.filter(item => item.sportTypeId == "1");
return filteredActivities;
});
eleventyConfig.addCollection("tagList", collections => {
const tags = collections
.getAll()
.reduce((tags, item) => tags.concat(item.data.tags), [])
.filter(tag => !!tag && !["notes", "all"].includes(tag))
.sort()
return Array.from(new Set(tags)).map(tag => ({
title: tag,
count: collections.getFilteredByTag(tag).length,
}))
})
eleventyConfig.addFilter("runsWithDescription", function(array) {
return array.filter(item => item.description);
});
// Add Eleventy setup here
/*
eleventyConfig.addCollection('stravaActivities', async function(collection) {
await refreshAccessToken();
return fetchStravaActivities();
});
*/
};