diff options
Diffstat (limited to 'src/content/dependencies/image.js')
-rw-r--r-- | src/content/dependencies/image.js | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/src/content/dependencies/image.js b/src/content/dependencies/image.js index db307a6..822efe3 100644 --- a/src/content/dependencies/image.js +++ b/src/content/dependencies/image.js @@ -1,4 +1,4 @@ -import {logInfo, logWarn} from '#cli'; +import {logWarn} from '#cli'; import {empty} from '#sugar'; export default { @@ -61,11 +61,14 @@ export default { reveal: {type: 'boolean', default: true}, lazy: {type: 'boolean', default: false}, + square: {type: 'boolean', default: false}, + dimensions: { + validate: v => v.isDimensions, + }, + alt: {type: 'string'}, - width: {type: 'number'}, - height: {type: 'number'}, attributes: { type: 'attributes', @@ -116,10 +119,6 @@ export default { const isMissingImageFile = missingImagePaths.includes(mediaSrc); - if (isMissingImageFile) { - logInfo`No image file for ${mediaSrc} - build again for list of missing images.`; - } - const willLink = !isMissingImageFile && (typeof slots.link === 'string' || slots.link); @@ -134,14 +133,26 @@ export default { !isMissingImageFile && !empty(contentWarnings); - const willSquare = slots.square; + const hasBothDimensions = + !!(slots.dimensions && + slots.dimensions[0] !== null && + slots.dimensions[1] !== null); + + const willSquare = + (hasBothDimensions + ? slots.dimensions[0] === slots.dimensions[1] + : slots.square); const imgAttributes = html.attributes([ {class: 'image'}, slots.alt && {alt: slots.alt}, - slots.width && {width: slots.width}, - slots.height && {height: slots.height}, + + slots.dimensions?.[0] && + {width: slots.dimensions[0]}, + + slots.dimensions?.[1] && + {width: slots.dimensions[1]}, ]); const isPlaceholder = @@ -220,11 +231,9 @@ export default { to('thumb.path', mediaSrcJpeg); } - const dimensions = getDimensionsOfImagePath(mediaSrc); - const availableThumbs = getThumbnailsAvailableForDimensions(dimensions); - - const [width, height] = dimensions; - const originalLength = Math.max(width, height) + const originalDimensions = getDimensionsOfImagePath(mediaSrc); + const availableThumbs = getThumbnailsAvailableForDimensions(originalDimensions); + const originalLength = Math.max(originalDimensions[0], originalDimensions[1]); const fileSize = (willLink && mediaSrc |