-
Notifications
You must be signed in to change notification settings - Fork 8
/
.eleventy.js
120 lines (106 loc) · 3.55 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
module.exports = function(config) {
// *** Collection imports
const collections = require("./eleventy/collections");
// *** Filter imports
const collectionFilters = require("./eleventy/filters/collections");
const urlFilters = require("./eleventy/filters/urls");
const dateFilters = require("./eleventy/filters/dates");
// *** Shortcode imports
const shortcodes = require("./eleventy/shortcodes");
// *** Misc imports
const env = require("./eleventy/env");
// *** Plugins
const rssPlugin = require("@11ty/eleventy-plugin-rss");
config.addPlugin(rssPlugin);
// Syntax highlighting
config.addPlugin(require("@11ty/eleventy-plugin-syntaxhighlight"));
// Typeset
if (env.is11tyProduction || env.is11tyStaging)
config.addPlugin(require("eleventy-plugin-typeset")());
// Safe external links
config.addPlugin(require("@hirusi/eleventy-plugin-safe-external-links"), {
pattern: "https{0,1}://", // RegExp pattern for external links
noopener: true, // Whether to include noopener
noreferrer: true, // Whether to include noreferrer
files: [
// What output file extensions to work on
".html"
]
});
// Minified HTML.
if (env.is11tyProduction || env.is11tyStaging) {
config.addPlugin(require("@sardine/eleventy-plugin-tinyhtml"));
}
const Image = require("@11ty/eleventy-img");
async function imageShortcode(src, alt, extraAttrs, sizes = "100vw") {
if (alt === undefined) {
// You bet we throw an error on missing alt (alt="" works okay)
throw new Error(`Missing \`alt\` on responsiveimage from: ${src}`);
}
let metadata = await Image(src, {
widths: [600, null],
formats: ["avif", "webp", "jpeg"],
urlPath: "/assets/img/",
outputDir: "./dist/assets/img/"
});
let highsrc = metadata.jpeg[metadata.jpeg.length - 1];
return `<picture>
${Object.values(metadata)
.map(imageFormat => {
return ` <source type="${
imageFormat[0].sourceType
}" srcset="${imageFormat
.map(entry => entry.srcset)
.join(", ")}" sizes="${sizes}">`;
})
.join("\n")}
<img
src="${highsrc.url}"
width="${highsrc.width}"
height="${highsrc.height}"
alt="${alt}"
loading="lazy"
decoding="async"
${extraAttrs}
>
</picture>`;
}
// *** Shortcodes
// Jekyll replacement for post_url tag as an 11ty shortcode
config.addShortcode("getUrl", shortcodes.postUrl);
config.addShortcode("getOwnerInfo", shortcodes.getOwnerInfo);
config.addShortcode("getPostType", shortcodes.getPostType);
config.addShortcode("isOldPost", shortcodes.isOldPost);
config.addLiquidShortcode("image", imageShortcode);
// *** Filters
// Dates
config.addFilter("friendlyDate", dateFilters.friendlyDate);
config.addFilter("dateToIso8601", dateFilters.dateToIso8601);
// Filter posts per tag
config.addFilter("byTag", collectionFilters.byTag);
// Absolute url
config.addFilter("absoluteUrl", urlFilters.absoluteUrl);
// The official RSS plugin exports only Nunjucks filters. They can be used with Liquid like so.
config.addFilter("htmlToAbsoluteUrls", rssPlugin.convertHtmlToAbsoluteUrls);
config.addFilter("dateToRfc3339", rssPlugin.dateToRfc3339);
config.addFilter(
"getNewestCollectionItemDate",
rssPlugin.getNewestCollectionItemDate
);
// *** Collections
// Articles
config.addCollection("primary", collections.primary);
// *** Misc
// Copy fonts as-is.
config.addPassthroughCopy({ "src/assets/font": "assets/font" });
return {
pathPrefix: "/", // useful for GitHub pages
dir: {
input: "./",
output: "dist",
includes: "src/includes",
layouts: "src/layouts",
data: "src/data"
}
};
};