Skip to content

Commit

Permalink
Add image links to original image
Browse files Browse the repository at this point in the history
Signed-off-by: David Martin <[email protected]>
  • Loading branch information
david-martin committed Nov 11, 2024
1 parent 8ec14a1 commit 569a263
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ module.exports = function(eleventyConfig) {

eleventyConfig.addPassthroughCopy("src/.well-known");

eleventyConfig.addPassthroughCopy("src/blog/**/*.png");

let markdownItOptions = {
html: true,
breaks: true,
Expand Down
7 changes: 6 additions & 1 deletion eleventy.config.images.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ module.exports = function(eleventyConfig) {
// Warning: Avif can be resource-intensive so take care!
let formats = ["avif", "webp", "auto"];
let input;
let originalSrc;
if(isFullUrl(src)) {
input = src;
originalSrc = src;
} else {
input = relativeToInputPath(this.page.inputPath, src);
originalSrc = '.' + src; // passthrough copy puts imags 1 level up
}

let metadata = await eleventyImage(input, {
Expand All @@ -46,6 +49,8 @@ module.exports = function(eleventyConfig) {
decoding: "async",
};

return eleventyImage.generateHTML(metadata, imageAttributes);
let imageHtml = eleventyImage.generateHTML(metadata, imageAttributes);

return `<a href="${originalSrc}">${imageHtml}</a>`;
});
};

0 comments on commit 569a263

Please sign in to comment.