Skip to content

Commit

Permalink
🐛 remove SVG handling for og:image
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesau committed Dec 12, 2024
1 parent c2edb20 commit db524fb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
9 changes: 2 additions & 7 deletions packages/@ourworldindata/utils/src/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,8 @@ export function getFeaturedImageFilename(gdoc: OwidGdoc): string | undefined {
},
},
(match) => {
const featuredImageSlug = match.content["featured-image"]
if (!featuredImageSlug) return undefined
// Social media platforms don't support SVG's for og:image, in which case, use the fallback PNG that the baker generates
// TODO: remove this and add an error if an author tries to use an SVG as a featured image
return getFilenameExtension(featuredImageSlug) === "svg"
? getFilenameAsPng(featuredImageSlug)
: featuredImageSlug
const featuredImageFilename = match.content["featured-image"]
return featuredImageFilename
}
)
.with({ content: { type: OwidGdocType.DataInsight } }, (gdoc) => {
Expand Down
12 changes: 10 additions & 2 deletions site/gdocs/OwidGdocPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
SiteFooterContext,
OwidGdocType,
spansToUnformattedPlainText,
get,
} from "@ourworldindata/utils"
import { getCanonicalUrl, getPageTitle } from "@ourworldindata/components"
import { DebugProvider } from "./DebugContext.js"
Expand Down Expand Up @@ -100,8 +101,15 @@ export default function OwidGdocPage({
) {
imageUrl = `${baseUrl}/${ARCHVED_THUMBNAIL_FILENAME}`
} else if (featuredImageFilename) {
// A hard-coded variant that doesn't need to know the image's width
imageUrl = `${CLOUDFLARE_IMAGES_URL}/${featuredImageFilename}/public`
const cloudflareId = get(gdoc, [
"imageMetadata",
featuredImageFilename,
"cloudflareId",
])
if (cloudflareId) {
// "public" is a hard-coded variant that doesn't need to know the image's width
imageUrl = `${CLOUDFLARE_IMAGES_URL}/${cloudflareId}/public`
}
}

return (
Expand Down

0 comments on commit db524fb

Please sign in to comment.