Skip to content

Commit d5f95c3

Browse files
Merge pull request #63 from Kuadrant/kuadrant-roadmap
Add post on kuadrant process & roadmap
2 parents 1519528 + dd57563 commit d5f95c3

File tree

9 files changed

+1301
-43
lines changed

9 files changed

+1301
-43
lines changed

.eleventy.js

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const string = require('string')
55
const slugify = s => string(s).slugify().toString()
66
const eleventyAsciidoc = require("eleventy-plugin-asciidoc");
77
const eleventyNavigationPlugin = require("@11ty/eleventy-navigation");
8+
const pluginImages = require("./eleventy.config.images.js");
89

910

1011
module.exports = function(eleventyConfig) {
@@ -21,6 +22,9 @@ module.exports = function(eleventyConfig) {
2122
linkify: true
2223
};
2324

25+
// Watch content images for the image pipeline.
26+
eleventyConfig.addWatchTarget("content/**/*.{svg,webp,png,jpeg}");
27+
2428
eleventyConfig.setLibrary(
2529
'md',
2630
markdownIt(markdownItOptions).use(markdownItAnchor, {
@@ -29,6 +33,7 @@ module.exports = function(eleventyConfig) {
2933
})
3034
);
3135
eleventyConfig.addPlugin(eleventyNavigationPlugin);
36+
eleventyConfig.addPlugin(pluginImages);
3237

3338
eleventyConfig.addFilter("readableDate", (dateObj, format, zone) => {
3439
// Formatting tokens for Luxon: https://moment.github.io/luxon/#/formatting?id=table-of-tokens

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
resources
33
_site
4+
/img

eleventy.config.images.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const path = require("path");
2+
const eleventyImage = require("@11ty/eleventy-img");
3+
4+
function relativeToInputPath(inputPath, relativeFilePath) {
5+
let split = inputPath.split("/");
6+
split.pop();
7+
8+
return path.resolve(split.join(path.sep), relativeFilePath);
9+
10+
}
11+
12+
function isFullUrl(url) {
13+
try {
14+
new URL(url);
15+
return true;
16+
} catch(e) {
17+
return false;
18+
}
19+
}
20+
21+
module.exports = function(eleventyConfig) {
22+
// Eleventy Image shortcode
23+
// https://www.11ty.dev/docs/plugins/image/
24+
eleventyConfig.addAsyncShortcode("image", async function imageShortcode(src, alt, widths, sizes) {
25+
// Full list of formats here: https://www.11ty.dev/docs/plugins/image/#output-formats
26+
// Warning: Avif can be resource-intensive so take care!
27+
let formats = ["avif", "webp", "auto"];
28+
let input;
29+
if(isFullUrl(src)) {
30+
input = src;
31+
} else {
32+
input = relativeToInputPath(this.page.inputPath, src);
33+
}
34+
35+
let metadata = await eleventyImage(input, {
36+
widths: widths || ["900,600,300"],
37+
formats,
38+
outputDir: path.join(eleventyConfig.dir.output, "img"), // Advanced usage note: `eleventyConfig.dir` works here because we’re using addPlugin.
39+
});
40+
41+
// TODO loading=eager and fetchpriority=high
42+
let imageAttributes = {
43+
alt,
44+
sizes,
45+
loading: "lazy",
46+
decoding: "async",
47+
};
48+
49+
return eleventyImage.generateHTML(metadata, imageAttributes);
50+
});
51+
};

0 commit comments

Comments
 (0)