Skip to content

Commit

Permalink
✨ handle extra cases with data insights atom feed images
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesau committed Aug 19, 2024
1 parent 0fc9338 commit f557fd4
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions site/gdocs/components/AtomArticleBlocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import { useImage } from "../utils.js"
import ArticleBlock, { Container, getLayout } from "./ArticleBlock.js"
import { BlockErrorFallback } from "./BlockErrorBoundary.js"
import {
LARGEST_IMAGE_WIDTH,
getFilenameExtension,
getFilenameWithoutExtension,
isNull,
LARGEST_IMAGE_WIDTH,
} from "@ourworldindata/utils"

export default function AtomArticleBlocks({
Expand Down Expand Up @@ -82,10 +83,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 extension = getFilenameExtension(image.filename)
return (
<img
src={`${BAKED_BASE_URL}${IMAGES_DIRECTORY}${filenameWithoutExtension}_${LARGEST_IMAGE_WIDTH}.${extension}`}
src={`${BAKED_BASE_URL}${IMAGES_DIRECTORY}${filenameWithoutExtension}${resizedWidth}.${extension}`}
alt={alt ?? image.defaultAlt}
width={image.originalWidth ?? undefined}
height={image.originalHeight ?? undefined}
Expand Down

0 comments on commit f557fd4

Please sign in to comment.