{"id":15679254,"url":"https://github.com/bholmesdev/11ty-image-optimization-demo","last_synced_at":"2025-05-07T09:28:10.133Z","repository":{"id":139409075,"uuid":"398043693","full_name":"bholmesdev/11ty-image-optimization-demo","owner":"bholmesdev","description":"A template to optimizing images based on markdown tags!","archived":false,"fork":false,"pushed_at":"2021-12-28T16:23:04.000Z","size":186,"stargazers_count":14,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-31T08:39:24.442Z","etag":null,"topics":["blog","talk"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bholmesdev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-19T18:48:10.000Z","updated_at":"2024-07-13T18:19:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"ea2181f6-47d6-4522-b62c-9768e639b779","html_url":"https://github.com/bholmesdev/11ty-image-optimization-demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bholmesdev%2F11ty-image-optimization-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bholmesdev%2F11ty-image-optimization-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bholmesdev%2F11ty-image-optimization-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bholmesdev%2F11ty-image-optimization-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bholmesdev","download_url":"https://codeload.github.com/bholmesdev/11ty-image-optimization-demo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252850315,"owners_count":21813941,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blog","talk"],"created_at":"2024-10-03T16:27:47.430Z","updated_at":"2025-05-07T09:28:10.119Z","avatar_url":"https://github.com/bholmesdev.png","language":"JavaScript","readme":"# 11ty image optimization by tag\n\nThis is a demo of how you can run [11ty's image plugin](https://www.11ty.dev/docs/plugins/image/) across any part of your site, no shortcodes required!\n\nThe goal:\n1. Find all `img` tags in a given template\n2. Replace with an optimized `picture` element\n\n⚠️ **Note:** this only works in 11ty's latest v1.0 beta. You can install this by adding the `@beta` flag to your 11ty install: `npm i @11ty/eleventy@beta`\n\n## Running and building\n\n1. Install dependencies using `npm i`\n2. Run `npm run dev` to spin up the dev server\n3. Run `npm run build` for production builds\n\n## The core setup\n\nThis code snippet (found in the `.eleventy.js` config) powers everything you're seeing:\n\n```js\nmodule.exports = function (eleventyConfig) {\n  eleventyConfig.addPassthroughCopy('img')\n  eleventyConfig.addExtension('md', {\n    read: true,\n    compile(markdown) {\n      return async function render(data) {\n        // let 11ty process markdown how it normally would\n        const html = await this.defaultRenderer(markdown);\n        const $ = cheerio.load(html);\n        \n        // if this markdown file has the \"blog\" tag applied...\n        if (data.tags?.includes('blog')) {\n          await Promise.all([\n            // loop over all the images in the document\n            $('img').toArray().map(async (img) =\u003e {\n              // grab the image attributes\n              const { src = '', alt = '', sizes = '100vw' } = img.attribs;\n              // convert to an optimized image\n              const optimizedImage = await imageShortcode(src, alt, sizes);\n              // and replace the image with an optimized one\n              $(img).replaceWith(optimizedImage);\n            })\n          ])\n        }\n\n        return $.html();\n      }\n    }\n  })\n}\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbholmesdev%2F11ty-image-optimization-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbholmesdev%2F11ty-image-optimization-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbholmesdev%2F11ty-image-optimization-demo/lists"}