Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = function (config) {

// Shortcodes
Object.keys(shortcodes).forEach((shortcodeName) => {
config.addShortcode(shortcodeName, shortcodes[shortcodeName])
config.addAsyncShortcode(shortcodeName, shortcodes[shortcodeName])
})

// Icon Sprite
Expand All @@ -51,7 +51,7 @@ module.exports = function (config) {
// Pass-through files
config.addPassthroughCopy('src/robots.txt')
config.addPassthroughCopy('src/site.webmanifest')
config.addPassthroughCopy('src/assets/images')
config.addPassthroughCopy('src/assets/images/favicon')
config.addPassthroughCopy('src/assets/fonts')

// Deep-Merge
Expand Down
23 changes: 22 additions & 1 deletion utils/shortcodes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
const Image = require("@11ty/eleventy-img");

module.exports = {
icon: function (name) {
image: async function imageShortcode(src, alt, sizes, width) {
src = "./src/assets/images/" + src;
let metadata = await Image(src, {
widths: width?[width] : [300, 600],
formats: ["avif", "jpeg"],
outputDir: "./dist/assets/images/",
urlPath: "/assets/images/"
});

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);
},
icon: async function (name) {
return `<svg class="icon icon--${name}" role="img" aria-hidden="true" width="24" height="24">
<use xlink:href="#icon-${name}"></use>
</svg>`
Expand Down