Open Graph images not working on next.js 15.3.1 despite being present in the HTML #79281
Answered
by
icyJoseph
h0ngwon
asked this question in
App Router
-
I have encountered an issue where my Open Graph images are no appearing when I share my page. This is My page : https://graphic.fan/p/t360y3XX import { Metadata } from "next";
import { notFound } from "next/navigation";
import { domain } from "@/global/utils/metadataUtil";
import PostDetailScreen from "@/module/community/detail/PostDetailScreen";
import { CommunityApi } from "@/data/api/communityApi";
interface Props {
params: Promise<{ serialNumber: string }>;
}
export default async function page({ params }: Props) {
const { serialNumber } = await params;
let post;
try {
post = await CommunityApi.getPostBySerialNumber(serialNumber);
} catch (e) {}
if (!post) notFound();
return <PostDetailScreen post={post} />;
}
export async function generateMetadata({ params }: Props): Promise<Metadata> {
const { serialNumber } = await params;
const post = await CommunityApi.getPostBySerialNumber(serialNumber);
let rawImageSrc: string;
const imgTagRegex = /<img[^>]+src=["']([^"']+)["'][^>]*>/i;
const match = post.html.match(imgTagRegex);
if (match && match[1]) {
rawImageSrc = match[1];
} else {
rawImageSrc = "/images/logo.png";;
}
let ogImageSrc: string;
if (rawImageSrc.startsWith("http://") || rawImageSrc.startsWith("https://")) {
ogImageSrc = rawImageSrc;
} else {
ogImageSrc = `${domain}${rawImageSrc.startsWith("/") ? rawImageSrc : `/${rawImageSrc}`}`;
}
return {
title: `${post.title} / 그래픽 - GRAPHIC`,
description: post.htmlText.trim(),
keywords: post.title,
authors: [{ name: post.user.nickname }],
robots: {
index: true,
follow: true,
},
openGraph: {
type: "article",
locale: "ko_KR",
url: `${domain}/p/${post.serialNumber}`,
siteName: "그래픽 - GRAPHIC",
title: post.title,
description: post.htmlText.trim(),
images: [
{
url: ogImageSrc,
alt: post.title,
},
],
},
alternates: {
canonical: `${domain}/p/${post.serialNumber}`,
},
};
} here is my Metadata Code. |
Beta Was this translation helpful? Give feedback.
Answered by
icyJoseph
May 16, 2025
Replies: 1 comment 3 replies
-
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
h0ngwon
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You seem to have logic that, looks for the
GRAPHIC_UUID
cookie on the incoming request, if not present, you redirect with aSet-Cookie
header. Bots, crawlers, SEO, and open-graph parsers, won't necessarily store that Cookie, when following the request. That's why they can't "see" your open graph data.