-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from stebrech/v3.1.0
see release notes
- Loading branch information
Showing
110 changed files
with
4,238 additions
and
2,484 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,71 @@ | ||
const path = require("path"); | ||
const eleventyImage = require("@11ty/eleventy-img"); | ||
const markdownIt = require("markdown-it"); | ||
const markdownItEleventyImg = require("markdown-it-eleventy-img"); | ||
|
||
module.exports = (eleventyConfig) => { | ||
const defaultImageWidths = [1210, 1044, 800, 400]; | ||
const defaultImageFormats = ["webp", "auto"]; | ||
const defaultImageSizes = "100vw"; | ||
|
||
// Eleventy Image shortcode | ||
// https://www.11ty.dev/docs/plugins/image/ | ||
eleventyConfig.addAsyncShortcode("image", async function imageShortcode(src, alt, widths, sizes) { | ||
// Full list of formats here: https://www.11ty.dev/docs/plugins/image/#output-formats | ||
// Warning: Avif can be resource-intensive so take care! | ||
let formats = ["webp", "auto"]; | ||
let metadata = await eleventyImage(src, { | ||
widths: widths || [1210, 1044, 800, 400], | ||
formats, | ||
widths: widths || defaultImageWidths, | ||
formats: defaultImageFormats, | ||
urlPath: "/assets/img/", | ||
outputDir: path.join(eleventyConfig.dir.output, "/assets/img/"), | ||
filenameFormat: function (id, src, width, format, options) { | ||
// id: hash of the original image | ||
// src: original image path | ||
// width: current width in px | ||
// format: current file format | ||
// options: set of options passed to the Image call | ||
const filename = path.basename(src, path.extname(src)); | ||
return `${filename}_${width}.${format}`; | ||
}, | ||
}); | ||
|
||
// TODO loading=eager and fetchpriority=high | ||
let imageAttributes = { | ||
alt, | ||
sizes: sizes || "100vw", | ||
sizes: sizes || defaultImageSizes, | ||
loading: "lazy", | ||
decoding: "async", | ||
}; | ||
return eleventyImage.generateHTML(metadata, imageAttributes); | ||
}); | ||
|
||
eleventyConfig.setLibrary( | ||
"md", | ||
markdownIt({ html: true, breaks: true }).use(markdownItEleventyImg, { | ||
imgOptions: { | ||
widths: defaultImageWidths, | ||
formats: defaultImageFormats, | ||
urlPath: "/assets/img/", | ||
outputDir: path.join(eleventyConfig.dir.output, "/assets/img/"), | ||
sharpOptions: { | ||
animated: true, | ||
limitInputPixels: false, | ||
}, | ||
filenameFormat: function (id, src, width, format, options) { | ||
// id: hash of the original image | ||
// src: original image path | ||
// width: current width in px | ||
// format: current file format | ||
// options: set of options passed to the Image call | ||
const filename = path.basename(src, path.extname(src)); | ||
return `${filename}_${width}.${format}`; | ||
}, | ||
}, | ||
globalAttributes: { | ||
class: "markdown-img", | ||
decoding: "async", | ||
sizes: defaultImageSizes, | ||
}, | ||
}), | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.