-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patheleventy.config.js
135 lines (112 loc) · 3.44 KB
/
eleventy.config.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
const path = require('path');
const Image = require('@11ty/eleventy-img');
const setupCollections = require('./lib/collections');
const setupSessions = require('./lib/sessions');
const setupFeed = require('./lib/feed');
const markdown = require('./lib/markdown');
const { formatInTimeZone } = require('date-fns-tz');
// Read timezone from site.json
const siteConfig = require('./src/_data/site.json');
const timezone = siteConfig.timezone || 'UTC'; // Default to 'UTC' if not specified
module.exports = (config) => {
setupCollections(config);
setupSessions(config);
setupFeed(config);
/*
Setup passthrough file copy
https://www.11ty.dev/docs/copy/
*/
config.addPassthroughCopy("src/assets/img/**/*");
config.addPassthroughCopy("src/assets/js/");
config.addPassthroughCopy("src/assets/favicons/");
config.addPassthroughCopy({
"src/_content/sponsors/*.{png,jpg,jpeg,webp,svg}": "sponsors/",
"src/_content/places/*.{png,jpg,jpeg,webp,svg}": "venue/",
});
config.addPassthroughCopy("CNAME");
config.addPassthroughCopy("ROBOTS.txt");
/*
Setup watch targets
https://www.11ty.dev/docs/watch-serve/#add-your-own-watch-targets
*/
config.addWatchTarget("src/assets/js/");
/*
Shortcodes
*/
// TODO: Accept widths or support different widths
config.addLiquidShortcode("image", async function(
src,
outputDir,
urlPath,
alt = "",
sizes,
classes = "") {
let metadata = await Image(src, {
widths: [180, 300, 600],
formats: ["webp"],
outputDir,
urlPath,
filenameFormat: function (id, src, width, format, options) {
// Get the original filename without the extension
const originalFilename = path.basename(src, path.extname(src));
return `${originalFilename}-${width}.${format}`;
},
});
let imageAttributes = {
class: classes,
alt,
sizes,
loading: "lazy",
decoding: "async",
};
return Image.generateHTML(metadata, imageAttributes);
});
config.addPairedShortcode("markdown", function(content = "") {
return markdown.render(content);
});
/*
Filters
*/
config.addFilter("markdown", function(content = "") {
return markdown.render(content);
});
config.addFilter("formatDateTime", function(date, format) {
return formatInTimeZone(date, timezone, format);
});
config.addFilter("find", function find(collection = [], slug = "") {
return collection.find(item => item.fileSlug === slug);
});
/* TODO: Make generic */
config.addFilter("talksByPresenter", function talksByPresenter(collection = [], slug = "") {
return collection.filter(item => item.data.presenter_slugs.includes(slug));
});
// Only build pages that aren't marked as drafts, usage below
// draft: true
config.addGlobalData("eleventyComputed.permalink", function() {
return (data) => {
if (data.draft) {
return false;
}
// Otherwise, use the permalink specified in the page front matter
return data.permalink;
}
});
/*
Misc configuration
*/
config.setFrontMatterParsingOptions({
excerpt: true,
excerpt_separator: "<!-- excerpt -->"
});
config.setLibrary("md", markdown);
return {
dir: {
input: "src",
output: "dist",
layouts: '_layouts',
},
// Use Liquid for templating
// https://www.11ty.dev/docs/languages/liquid/
htmlTemplateEngine: "liquid"
}
};