Add secureUrl and type to OG image metadata

This commit is contained in:
Francisco Ignácio Fontoura Solla 2026-05-01 02:55:37 -03:00
parent 9313eb7f29
commit 260f75abe8

View file

@ -19,7 +19,9 @@ const truncate = (text: string, max: number) =>
text.length <= max ? text : `${text.slice(0, max - 1).trimEnd()}…` text.length <= max ? text : `${text.slice(0, max - 1).trimEnd()}…`
const toAbsoluteUrl = (url: string, siteUrl: string) => const toAbsoluteUrl = (url: string, siteUrl: string) =>
/^https?:\/\//i.test(url) ? url : `${stripTrailingSlash(siteUrl)}${url.startsWith('/') ? '' : '/'}${url}` /^https?:\/\//i.test(url)
? url
: `${stripTrailingSlash(siteUrl)}${url.startsWith('/') ? '' : '/'}${url}`
export async function generateStaticParams() { export async function generateStaticParams() {
const payload = await getDocuments('petition') const payload = await getDocuments('petition')
@ -67,14 +69,17 @@ export async function generateMetadata({
petition.title, petition.title,
] ]
const ogImages = const imageUrl = image?.url ? toAbsoluteUrl(image.url, siteUrl) : undefined
image?.url
const ogImages = imageUrl
? [ ? [
{ {
url: toAbsoluteUrl(image.url, siteUrl), url: imageUrl,
secureUrl: imageUrl,
width: image.width ?? undefined, width: image.width ?? undefined,
height: image.height ?? undefined, height: image.height ?? undefined,
alt: image.alt, alt: image.alt,
type: image.mimeType ?? undefined,
}, },
] ]
: [] : []