From cede049f15c9bdcf3991656070c3067d8f152753 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 3 Dec 2026 21:54:36 -0700 Subject: feed: a link-preview crawler waits up to 6 s for a post's page, so the shared card shows the post. "can we add some meta tags that would show a better title/description/content preview for posts when i link to them on social media?" (Adam, 2026-12-04, with a Telegram card for his fresh nevent link showing the generic Coinos card). The post pages already carry the author as og:title, the text as og:description and the post's picture or the author's face as og:image, but a post the server hadn't cached got 500 ms (profiles 2 s) before the plain page went out, and a post shared right after it was written misses that: Telegram fetched it once and kept the site's card. Link-preview crawlers (Telegram, X, Facebook, WhatsApp, Slack, Discord, LinkedIn, Mastodon & co, search bots: isPreviewBot) now get up to 6 s; people keep the short wait. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VMan6WoqaQDYdpWkatPCar (feed copy, same as coinosv3-server) --- feed/note-page.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'feed/note-page.js') diff --git a/feed/note-page.js b/feed/note-page.js index 89b2f43..ac51f77 100644 --- a/feed/note-page.js +++ b/feed/note-page.js @@ -19,6 +19,11 @@ export const NOTE_RELAYS = ['wss://relay.damus.io', 'wss://nos.lol', 'wss://rela // where kind 0s live when the conversation relays lack them const PROFILE_RELAYS = ['wss://purplepag.es', 'wss://user.kindpag.es']; const BUDGET_MS = 500; +// A link-preview crawler reads the page once and keeps that card (Telegram, +// 2026-12-04: a fresh post shared at once got the site's card because its +// thread took longer than BUDGET_MS); it can wait for the real thing. +export const BOT_BUDGET_MS = 6000; +export const isPreviewBot = (ua) => /bot\b|bot\/|crawler|spider|facebookexternalhit|facebookcatalog|whatsapp|telegram|slack|discord|twitter|linkedin|skype|embedly|iframely|mastodon|pleroma|misskey|akkoma|signal|vkshare|redditbot|applebot|bingpreview|google|yandex|duckduck|pinterest|tumblr|snapchat|preview/i.test(String(ua || '')); const FRESH_MS = 60_000; // a thread younger than this is served as is const KEEP_MS = 6 * 3600_000; // older, it's still served while a refresh runs const MAX_THREADS = 500; @@ -179,7 +184,7 @@ export async function notePageResponse(req, { index, threads }) { const headers = { 'Content-Type': 'text/html; charset=utf-8', 'Cache-Control': 'no-cache, must-revalidate' }; if (!ref) return new Response(html, { headers }); ref.path = u.pathname.slice(1); - const data = await threads.get(ref).catch(() => null); + const data = await threads.get(ref, isPreviewBot(req.headers.get('user-agent')) ? BOT_BUDGET_MS : undefined).catch(() => null); const proto = req.headers.get('x-forwarded-proto') || 'https'; const host = req.headers.get('x-forwarded-host') || req.headers.get('host'); return new Response(data ? renderNotePage(html, data, ref, host ? proto + '://' + host : '') : html, { headers }); -- cgit v1.2.3