adjusted image sizes

This commit is contained in:
madrilene 2023-04-11 13:38:26 +02:00
parent 3cac6fd25c
commit 2e7ebcb112
5 changed files with 21 additions and 9 deletions

View file

@ -2,13 +2,18 @@ const Image = require('@11ty/eleventy-img');
const path = require('path'); const path = require('path');
const htmlmin = require('html-minifier-terser'); const htmlmin = require('html-minifier-terser');
const imageShortcodePlaceholder = async (src, alt, caption, sizes = '100vw') => { const imageShortcodePlaceholder = async (
src,
alt,
caption,
sizes = '(min-width: 55rem) 820px, 100vw'
) => {
if (!alt) { if (!alt) {
throw new Error(`Missing \`alt\` on myImage from: ${src}`); throw new Error(`Missing \`alt\` on myImage from: ${src}`);
} }
let metadata = await Image(src, { let metadata = await Image(src, {
widths: [400, 700, 1280], widths: [320, 570, 820],
formats: ['avif', 'webp', 'jpeg'], formats: ['avif', 'webp', 'jpeg'],
urlPath: '/assets/images/', urlPath: '/assets/images/',
outputDir: './dist/assets/images/', outputDir: './dist/assets/images/',
@ -20,7 +25,7 @@ const imageShortcodePlaceholder = async (src, alt, caption, sizes = '100vw') =>
} }
}); });
let lowsrc = metadata.jpeg[0]; let lowsrc = metadata.jpeg[metadata.jpeg.length - 1];
// getting the url to use // getting the url to use
let imgSrc = src; let imgSrc = src;

View file

@ -1,6 +1,6 @@
{ {
"name": "eleventy-excellent", "name": "eleventy-excellent",
"version": "1.4.7", "version": "1.4.8",
"description": "Eleventy starter based on the workflow suggested by Andy Bell's buildexcellentwebsit.es.", "description": "Eleventy starter based on the workflow suggested by Andy Bell's buildexcellentwebsit.es.",
"author": "Lene Saile", "author": "Lene Saile",
"license": "ISC", "license": "ISC",

View file

@ -11,6 +11,6 @@
} }
.blog img { .blog img {
width: 100%; max-inline-size: var(--max-img-width, 100%);
height: auto; block-size: auto;
} }

View file

@ -1,4 +1,4 @@
.page img { .page img {
width: 100%; max-inline-size: var(--max-img-width, 100%);
height: auto; block-size: auto;
} }

View file

@ -6,6 +6,13 @@ date: 2022-10-12
This starter uses Eleventy's build-time image transformations. Find more info on https://www.11ty.dev/docs/plugins/image/ and edit settings in `config/shortcodes/imagePlaceholder`. This starter uses Eleventy's build-time image transformations. Find more info on https://www.11ty.dev/docs/plugins/image/ and edit settings in `config/shortcodes/imagePlaceholder`.
For now there are three image sizes: 320px, 550px and 820px.
820px is the maximum size, equivalent to the width set for our content wrapper in `prose.css`: `--wrapper-max-width: 55rem;`.
The `sizes` attribute is set to `sizes = '(min-width: 55rem) 820px, 100vw'`.
If you want to adjust the wrapper width you should also adjust the image size in the shortcode accordingly.
## Syntax ## Syntax
{% raw %} {% raw %}
@ -16,7 +23,7 @@ This starter uses Eleventy's build-time image transformations. Find more info on
{% endraw %} {% endraw %}
Or add your own `sizes` attribute (note how I set an empty string for the caption): Add your own `sizes` attribute (note how I set an empty string for the caption):
{% raw %} {% raw %}