-
Notifications
You must be signed in to change notification settings - Fork 2
/
.eleventy.js
124 lines (115 loc) · 4.34 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
const { EleventyRenderPlugin } = require("@11ty/eleventy");
const { EleventyServerlessBundlerPlugin } = require("@11ty/eleventy");
const Image = require("@11ty/eleventy-img");
async function imageShortcode(src, alt, sizes) {
let metadata = await Image(src, {
widths: [500, 800, 1000],
formats: ["avif", "jpeg"],
outputDir: "./_site/img/"
});
let imageAttributes = {
alt,
sizes,
loading: "lazy",
decoding: "async",
};
// You bet we throw an error on missing alt in `imageAttributes` (alt="" works okay)
return Image.generateHTML(metadata, imageAttributes);
}
module.exports = function (eleventyConfig) {
// Sorting filter
eleventyConfig.addFilter("customSort", function (tasksArr, queryStr) {
// No sort is set
if (!queryStr) { return tasksArr }
let tasks = tasksArr;
// Split sort parameters by ","
let queryArr = queryStr.split(",")
// Construct an object based on the query
let queryObj = {};
queryArr.forEach(element => {
let key = element.split(":")[0];
let value = element.split(":")[1]
queryObj[key] = value;
});
// return queryObj;
tasks = tasks.sort((a, b) => {
for (const parameter in queryObj) {
if (Object.hasOwnProperty.call(queryObj, parameter)) {
let asc;
// Check if query is ascending or descending
queryObj[parameter] == "asc" ? asc = true : asc = false;
let compA;
let compB;
switch (parameter) {
case "prio":
compA = a.priority
compB = b.priority
if (!asc) {
// Reverse the order on a descending call
if (compA < compB) { return 1; }
if (compA > compB) { return -1; }
return 0;
}
if (compA < compB) { return -1; }
if (compA > compB) { return 1; }
return 0;
break;
case "proj":
compA = a.project_id;
compB = b.project_id;
case "due":
console.log("comparing date")
compA = new Date(a.due?.date) || 0;
compB = new Date(b.due?.date) || 0;
if (!asc) {
// reverse the sort on a descending call
return (compB - compA);
}
return (compA - compB);
case "alph":
compA = a.content;
compB = b.content;
default:
break;
}
if (!asc) {
if (compA < compB) { return 1; }
if (compA > compB) { return -1; }
return 0;
}
}
if (compA < compB) { return -1; }
if (compA > compB) { return 1; }
return 0;
}
}
)
return tasks;
})
// Filters
const markdownIt = require("markdown-it");
const markdownItRenderer = new markdownIt();
eleventyConfig.addFilter('markdownify', (str) => {
return markdownItRenderer.renderInline(str);
});
eleventyConfig.addNunjucksAsyncShortcode("image", imageShortcode);
// Plugins
eleventyConfig.addPlugin(EleventyRenderPlugin);
eleventyConfig.addPlugin(EleventyServerlessBundlerPlugin, {
name: "dynamic",
functionsDir: "./netlify/functions/"
});
// Passthrough
eleventyConfig.addPassthroughCopy("src/css/");
eleventyConfig.addPassthroughCopy("src/assets");
eleventyConfig.addPassthroughCopy("src/js/");
return {
dir: {
input: "src",
output: "_site",
includes: '_includes',
layouts: 'layouts',
data: '_data'
},
};
};