Skip to content

Commit 6f74ab3

Browse files
committed
Redo responsive img w/ new knowledge
1 parent ec746d0 commit 6f74ab3

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

_includes/shortcodes/responsive-image.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@ module.exports = async (src, alt, outputFormat = 'jpeg') => {
1414
});
1515

1616
const lowestSrc = stats[outputFormat][0];
17-
const sizes = '(max-width: 400px) 400px, (max-width: 800px) 800px, 100vw';
18-
const sourceBlock = Object.values(stats).map((imageFormat) => `<source type="image/${imageFormat[0].format}" srcset="${imageFormat.map((entry) => `${entry.url} ${entry.width}w`).join(', ')}" sizes="${sizes}">`).join('\n');
17+
const srcset = Object.values(stats).map((imageFormat) => `${imageFormat.map((entry) => `${entry.url} ${entry.width}w`).join(', ')}`).join('\n');
1918

20-
return `<picture class="image">
21-
${sourceBlock}
22-
<img src="${lowestSrc.url}" width="${lowestSrc.width}" height="${lowestSrc.height}" alt="${alt}" loading="lazy">`;
19+
return `<img src="${lowestSrc.url}" srcset="${srcset}" width="${lowestSrc.width}" height="${lowestSrc.height}" alt="${alt}" loading="lazy">`;
2320
} catch (err) {
2421
// eslint-disable-next-line no-console
2522
console.error('Responsive Image: eleventy-img error:', err);

_layouts/base.liquid

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@
5959
</div>
6060

6161
{%- if page.url == '/' -%}
62-
{% responsiveImage "./assets/img/carlos-alfonso-AlBgcDfDG_s-unsplash_min.jpg", "Austin Skyline by Carlos Alfonso on Unsplash" %}
62+
<figure class="image">
63+
{% responsiveImage "./assets/img/carlos-alfonso-AlBgcDfDG_s-unsplash_min.jpg", "Austin Skyline by Carlos Alfonso on Unsplash" %}
64+
</figure>
6365
{%- endif -%}
6466
</header>
6567

0 commit comments

Comments
 (0)