Skip to content

Commit f5f907b

Browse files
committed
Fixes for og:image to show up - was: 404
1 parent 81b9edf commit f5f907b

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/layouts/ContentPageLayout.astro

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ interface Props {
3333
headings?: MarkdownHeading[];
3434
showTitleAsH1?: boolean;
3535
showBreadcrumbs?: boolean;
36+
ogImage?: URL | undefined;
3637
}
3738
38-
const { title, description, headings, showTitleAsH1 = true, showBreadcrumbs = true } = Astro.props;
39+
const { title, description, headings, showTitleAsH1 = true, showBreadcrumbs = true, ogImage} = Astro.props;
3940
---
4041

41-
<BaseLayout title={title} description={description}>
42+
<BaseLayout title={title} description={description} ogImage={ogImage}>
4243
<div class="relative mx-18 px-0 min-h-[calc(100vh-4rem)]">
4344

4445
<div class={`

src/pages/blog/[...slug].astro

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { formatDate } from '@/components/blog/blogUtils';
66
import AuthorCard from '@/components/blog/AuthorCard.astro';
77
import MDXComponents from '@/components/mdx/MDXComponents';
88
import "@/styles/breadcrumbs.css";
9-
import { Image } from "astro:assets";
9+
import { Image, getImage } from "astro:assets";
1010
1111
/**
1212
* Magic required function for dynamic routes; deteremines the slug
@@ -59,8 +59,10 @@ let ogImageMetadata;
5959
if (ogImageFilename) {
6060
const ogImagePath = imageDir + ogImageFilename;
6161
if (images[ogImagePath]) {
62-
ogImageMetadata = images[ogImagePath]();
63-
ogImageUrl = new URL(ogImageMetadata.src, Astro.site);
62+
ogImageMetadata = await images[ogImagePath]();
63+
// Use getImage to get the processed public URL for og:image
64+
const processedOgImage = await getImage({ src: ogImageMetadata.default });
65+
ogImageUrl = new URL(processedOgImage.src, Astro.site);
6466
}
6567
}
6668
@@ -81,7 +83,7 @@ if (ogImageFilename) {
8183
{ogImageMetadata && (
8284
<div class="w-full mb-8 -mt-8">
8385
<Image
84-
src={ogImageMetadata}
86+
src={ogImageMetadata.default}
8587
alt={post.data.title}
8688
class="w-full h-auto rounded-lg"
8789
/>

0 commit comments

Comments
 (0)