Skip to content

Commit

Permalink
Merge pull request #3180 from owid/image-filename-escaping
Browse files Browse the repository at this point in the history
🐛 fix double uriEncoding of gdocs og:image URLs
  • Loading branch information
ikesau authored Feb 8, 2024
2 parents a9497ba + cdfef18 commit 26fa7b8
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 15 deletions.
13 changes: 1 addition & 12 deletions packages/@ourworldindata/utils/src/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion packages/@ourworldindata/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ export {
type SourceProps,
generateSourceProps,
getFeaturedImageFilename,
filenameToUrl,
} from "./image.js"

export { Tippy, TippyIfInteractive } from "./Tippy.js"
Expand Down
4 changes: 2 additions & 2 deletions site/gdocs/OwidGdocPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 26fa7b8

Please sign in to comment.