From 39d4c6fc93ea61fa2d05dc447cb299b5cb560e2e Mon Sep 17 00:00:00 2001 From: crbon Date: Thu, 22 Jan 2026 13:11:59 +1000 Subject: [PATCH] feat(route): enhance Open Graph metadata handling for bots - Refactored the GET route to dynamically generate Open Graph and Twitter meta tags based on available link metadata. - Added support for conditional rendering of meta tags, improving SEO and social media sharing capabilities. - Ensured that the response includes appropriate meta tags for both Open Graph and Twitter cards, enhancing link previews. --- src/app/(collect)/q/[slug]/route.ts | 34 ++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/app/(collect)/q/[slug]/route.ts b/src/app/(collect)/q/[slug]/route.ts index f97ab7e2..3b56cc16 100644 --- a/src/app/(collect)/q/[slug]/route.ts +++ b/src/app/(collect)/q/[slug]/route.ts @@ -55,11 +55,22 @@ export async function GET(request: Request, { params }: { params: Promise<{ slug userAgent, ); - if (isBot && (link.ogTitle || link.ogDescription || link.ogImageUrl)) { + if (isBot) { const ogTitle = escapeHtml(link.ogTitle || link.name); const ogDescription = escapeHtml(link.ogDescription || ''); const ogImageUrl = escapeHtml(link.ogImageUrl || ''); - const url = escapeHtml(link.url); + const ogDescriptionTag = ogDescription + ? `` + : ''; + const ogImageTag = ogImageUrl ? `` : ''; + const twitterCard = ogImageUrl ? 'summary_large_image' : 'summary'; + const metaDescriptionTag = ogDescription + ? `` + : ''; + const twitterDescriptionTag = ogDescription + ? `` + : ''; + const twitterImageTag = ogImageUrl ? `` : ''; return new Response( ` @@ -68,14 +79,21 @@ export async function GET(request: Request, { params }: { params: Promise<{ slug ${ogTitle} + + + ${metaDescriptionTag} + + + - - - - + + ${ogDescriptionTag} + ${ogImageTag} + + - - + ${twitterDescriptionTag} + ${twitterImageTag}