diff --git a/src/app/(collect)/q/[slug]/route.ts b/src/app/(collect)/q/[slug]/route.ts index 3b56cc16..b702a244 100644 --- a/src/app/(collect)/q/[slug]/route.ts +++ b/src/app/(collect)/q/[slug]/route.ts @@ -1,5 +1,6 @@ export const dynamic = 'force-dynamic'; +import { isbot } from 'isbot'; import { NextResponse } from 'next/server'; import { POST } from '@/app/api/send/route'; import type { Link } from '@/generated/prisma/client'; @@ -16,6 +17,14 @@ function escapeHtml(str: string): string { .replace(/'/g, '''); } +function metaTag(property: string, content: string | undefined, isName = false): string { + if (!content) return ''; + const escaped = escapeHtml(content); + return isName + ? `` + : ``; +} + export async function GET(request: Request, { params }: { params: Promise<{ slug: string }> }) { const { slug } = await params; @@ -50,27 +59,12 @@ export async function GET(request: Request, { params }: { params: Promise<{ slug } const userAgent = request.headers.get('user-agent') || ''; - const isBot = - /facebookexternalhit|twitterbot|linkedinbot|whatsapp|slackbot|discordbot|telegrambot|applebot|bingbot|googlebot/i.test( - userAgent, - ); - if (isBot) { - const ogTitle = escapeHtml(link.ogTitle || link.name); - const ogDescription = escapeHtml(link.ogDescription || ''); - const ogImageUrl = escapeHtml(link.ogImageUrl || ''); - const ogDescriptionTag = ogDescription - ? `` - : ''; - const ogImageTag = ogImageUrl ? `` : ''; + if (isbot(userAgent)) { + const ogTitle = link.ogTitle || link.name; + const ogDescription = link.ogDescription || undefined; + const ogImageUrl = link.ogImageUrl || undefined; const twitterCard = ogImageUrl ? 'summary_large_image' : 'summary'; - const metaDescriptionTag = ogDescription - ? `` - : ''; - const twitterDescriptionTag = ogDescription - ? `` - : ''; - const twitterImageTag = ogImageUrl ? `` : ''; return new Response( ` @@ -78,29 +72,29 @@ export async function GET(request: Request, { params }: { params: Promise<{ slug
-Redirecting to ${escapeHtml(link.url)}...
+ - `, + `, { headers: { 'content-type': 'text/html', + 'cache-control': 's-maxage=300, stale-while-revalidate', }, }, );