Skip to content

Commit

Permalink
Merge pull request #4270 from owid/fix-default-thumbnails-in-search
Browse files Browse the repository at this point in the history
🐛 fix default gdoc thumbnails not rendering in gdocs
  • Loading branch information
ikesau authored Dec 9, 2024
2 parents 1e169ad + 4c9b3b4 commit 6fb21e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion baker/algolia/utils/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function getGdocThumbnailUrl(gdoc: OwidGdocPostInterface): string {
if (gdoc.content["featured-image"]) {
return getThumbnailPath(gdoc.content["featured-image"])
}
return `/${DEFAULT_GDOC_FEATURED_IMAGE}`
return `/images/published/${DEFAULT_GDOC_FEATURED_IMAGE}`
}

function generateGdocRecords(
Expand Down
9 changes: 8 additions & 1 deletion site/search/SearchPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
groupBy,
uniqBy,
Region,
DEFAULT_GDOC_FEATURED_IMAGE,
} from "@ourworldindata/utils"
import {
InstantSearch,
Expand Down Expand Up @@ -65,6 +66,12 @@ import { ChartHit } from "./ChartHit.js"
const siteAnalytics = new SiteAnalytics()

function PagesHit({ hit }: { hit: IPageHit }) {
// a temporary fix for articles that have been indexed without the directory
const src =
hit.thumbnailUrl === `/${DEFAULT_GDOC_FEATURED_IMAGE}`
? `/images/published/${DEFAULT_GDOC_FEATURED_IMAGE}`
: hit.thumbnailUrl

return (
<a
href={`${BAKED_BASE_URL}/${hit.slug}`}
Expand All @@ -76,7 +83,7 @@ function PagesHit({ hit }: { hit: IPageHit }) {
{hit.thumbnailUrl && (
<div className="search-results__page-hit-img-container">
<img
src={hit.thumbnailUrl}
src={src}
role="presentation"
className="search-results__page-hit-img"
/>
Expand Down

0 comments on commit 6fb21e8

Please sign in to comment.