Skip to content

Commit 45a5e42

Browse files
ppekrolclaude
andcommitted
Fix homepage images broken by ideal-image plugin
The @docusaurus/plugin-ideal-image webpack loader transforms image imports into objects instead of plain URL strings. LazyImage now resolves these objects back to URLs so CardWithImage displays correctly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f471969 commit 45a5e42

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/components/Common/LazyImage.tsx

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ export interface LazyImageProps extends React.ImgHTMLAttributes<HTMLImageElement
77
minContentHeight?: number;
88
}
99

10+
// @docusaurus/plugin-ideal-image transforms image imports into objects like
11+
// { src: { src: "/img/file.hash.png" } } instead of plain URL strings.
12+
// Extract the URL string from such objects.
13+
function toUrl(value: unknown): string | undefined {
14+
if (typeof value === "string") return value;
15+
if (!value || typeof value !== "object") return undefined;
16+
const { src } = value as Record<string, unknown>;
17+
if (typeof src === "string") return src;
18+
if (src && typeof src === "object") return (src as Record<string, unknown>).src as string;
19+
return undefined;
20+
}
21+
1022
export default function LazyImage({
1123
imgSrc,
1224
src,
@@ -53,17 +65,16 @@ export default function LazyImage({
5365

5466
function getSources({ imgSrc, src }: Pick<LazyImageProps, "imgSrc" | "src">): ThemedImageProps["sources"] {
5567
if (src) {
56-
return {
57-
light: src,
58-
dark: src,
59-
};
68+
return { light: src, dark: src };
69+
}
70+
71+
if (imgSrc && typeof imgSrc === "object" && "light" in imgSrc && "dark" in imgSrc) {
72+
return imgSrc;
6073
}
6174

62-
if (typeof imgSrc === "string") {
63-
return {
64-
light: imgSrc,
65-
dark: imgSrc,
66-
};
75+
const resolved = toUrl(imgSrc);
76+
if (resolved) {
77+
return { light: resolved, dark: resolved };
6778
}
6879

6980
return imgSrc;

0 commit comments

Comments
 (0)