From cdfef18a43625a1e9a82b8ac931b61449a1b0ffc Mon Sep 17 00:00:00 2001 From: Ike Saunders Date: Thu, 8 Feb 2024 15:10:47 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20double=20uriEncoding=20of?= =?UTF-8?q?=20gdocs=20og:image=20URLs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/@ourworldindata/utils/src/image.ts | 13 +------------ packages/@ourworldindata/utils/src/index.ts | 1 - site/gdocs/OwidGdocPage.tsx | 4 ++-- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/packages/@ourworldindata/utils/src/image.ts b/packages/@ourworldindata/utils/src/image.ts index cceac79a0d0..4ac7124a30c 100644 --- a/packages/@ourworldindata/utils/src/image.ts +++ b/packages/@ourworldindata/utils/src/image.ts @@ -3,12 +3,7 @@ Common utlities for deriving properties from image metadata. */ import { traverseEnrichedBlocks } from "./Util.js" -import { - OwidGdoc, - OwidGdocType, - IMAGES_DIRECTORY, - ImageMetadata, -} from "@ourworldindata/types" +import { OwidGdoc, OwidGdocType, ImageMetadata } from "@ourworldindata/types" import { match, P } from "ts-pattern" export function getSizes( @@ -51,12 +46,6 @@ export function getFilenameAsPng(filename: ImageMetadata["filename"]): string { return `${getFilenameWithoutExtension(filename)}.png` } -/** - * example-image.png -> https://ourworldindata.org/uploads/published/example-image.png - */ -export const filenameToUrl = (filename: string, baseUrl: string): string => - new URL(`${IMAGES_DIRECTORY}${getFilenameAsPng(filename)}`, baseUrl).href - export type SourceProps = { media: string | undefined srcSet: string diff --git a/packages/@ourworldindata/utils/src/index.ts b/packages/@ourworldindata/utils/src/index.ts index 7587daa0ee4..422f695cdbd 100644 --- a/packages/@ourworldindata/utils/src/index.ts +++ b/packages/@ourworldindata/utils/src/index.ts @@ -365,7 +365,6 @@ export { type SourceProps, generateSourceProps, getFeaturedImageFilename, - filenameToUrl, } from "./image.js" export { Tippy, TippyIfInteractive } from "./Tippy.js" diff --git a/site/gdocs/OwidGdocPage.tsx b/site/gdocs/OwidGdocPage.tsx index baff5bb4490..5a7cdbad033 100644 --- a/site/gdocs/OwidGdocPage.tsx +++ b/site/gdocs/OwidGdocPage.tsx @@ -9,10 +9,10 @@ import { OwidGdoc as OwidGdocUnionType, SiteFooterContext, OwidGdocType, - filenameToUrl, } from "@ourworldindata/utils" import { DebugProvider } from "./DebugContext.js" import { match, P } from "ts-pattern" +import { IMAGES_DIRECTORY } from "@ourworldindata/types" declare global { interface Window { @@ -75,7 +75,7 @@ export default function OwidGdocPage({ imageUrl={ // uriEncoding is taken care of inside the Head component featuredImageFilename - ? filenameToUrl(featuredImageFilename, baseUrl) + ? `${baseUrl}${IMAGES_DIRECTORY}${featuredImageFilename}` : undefined } baseUrl={baseUrl}