Skip to content

Commit

Permalink
🐛 fix data insight atom feed image height / width
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesau committed Aug 29, 2024
1 parent 55a1eb0 commit 8bbd922
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions site/gdocs/components/AtomArticleBlocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { BlockErrorFallback } from "./BlockErrorBoundary.js"
import {
getFilenameExtension,
getFilenameWithoutExtension,
isNull,
LARGEST_IMAGE_WIDTH,
} from "@ourworldindata/utils"

Expand Down Expand Up @@ -83,28 +82,25 @@ function Image({
const filenameWithoutExtension = encodeURIComponent(
getFilenameWithoutExtension(image.filename)
)
const resizedWidth = match(image.originalWidth)
.when(
(width) => isNull(width),
() => ""
)
.when(
(width) => width <= LARGEST_IMAGE_WIDTH,
() => ""
)
.when(
(width) => width > LARGEST_IMAGE_WIDTH,
() => `_${LARGEST_IMAGE_WIDTH}`
)
.otherwise(() => "")
const widthSuffix =
image.originalWidth && image.originalWidth > LARGEST_IMAGE_WIDTH
? `_${LARGEST_IMAGE_WIDTH}`
: ""
const aspectRatio =
image.originalWidth && image.originalHeight
? image.originalWidth / image.originalHeight
: null
const height = aspectRatio
? Math.round(LARGEST_IMAGE_WIDTH / aspectRatio)
: undefined

const extension = getFilenameExtension(image.filename)
return (
<img
src={`${BAKED_BASE_URL}${IMAGES_DIRECTORY}${filenameWithoutExtension}${resizedWidth}.${extension}`}
src={`${BAKED_BASE_URL}${IMAGES_DIRECTORY}${filenameWithoutExtension}${widthSuffix}.${extension}`}
alt={alt ?? image.defaultAlt}
width={image.originalWidth ?? undefined}
height={image.originalHeight ?? undefined}
width={LARGEST_IMAGE_WIDTH}
height={height}
/>
)
}

0 comments on commit 8bbd922

Please sign in to comment.