diff options
| author | Adam Soltys <[email protected]> | 2026-12-03 21:54:29 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-12-03 21:54:29 -0700 |
| commit | 42e866f1041801a9d8c3e9ca6527383d27778500 (patch) | |
| tree | 624e97b54afe12ccf376ada0eb190335e4c7cc1a /tools | |
| parent | 9cb28c714529130a9abf01db489335f764cc853a (diff) | |
| download | coinosv3-server-42e866f1041801a9d8c3e9ca6527383d27778500.tar.gz coinosv3-server-42e866f1041801a9d8c3e9ca6527383d27778500.zip | |
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 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VMan6WoqaQDYdpWkatPCar
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/note-page-bot-test.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tools/note-page-bot-test.js b/tools/note-page-bot-test.js new file mode 100644 index 0000000..e8ec523 --- /dev/null +++ b/tools/note-page-bot-test.js @@ -0,0 +1,32 @@ +// A link-preview crawler (Telegram, Slack, X…) reads a post's page once and +// keeps that card, so it waits for the thread a visitor wouldn't: a post that +// takes 1.5 s to find gets its own title and text for TelegramBot and the plain +// page (on time) for a browser. Run: bun tools/note-page-bot-test.js +import assert from 'node:assert/strict'; +import { generateSecretKey, getPublicKey, finalizeEvent } from 'nostr-tools/pure'; +import { neventEncode } from 'nostr-tools/nip19'; +import { createThreadCache, notePageResponse, isPreviewBot } from '../feed/note-page.js'; + +const sk = generateSecretKey(), pk = getPublicKey(sk); +const post = finalizeEvent({ kind: 1, created_at: 1, tags: [], content: 'Moving coins out of old addresses into a fresh wallet', }, sk); +const prof = finalizeEvent({ kind: 0, created_at: 1, tags: [], content: JSON.stringify({ name: 'Adam' }) }, sk); +const html = '<html><head><title>Coinos</title><!--site-tags--><meta property="og:title" content="Coinos"><!--/site-tags--></head><body></body></html>'; +const path = '/' + neventEncode({ id: post.id, author: pk }); +const slow = () => createThreadCache({ build: () => new Promise((r) => setTimeout(() => r({ v: 1, root: post, replies: [], profiles: [prof] }), 1500)) }); +const req = (ua) => new Request('https://v3.coinos.io' + path, { headers: { 'user-agent': ua } }); + +for (const ua of ['TelegramBot (like TwitterBot)', 'Mozilla/5.0 (compatible; Discordbot/2.0; +https://discordapp.com)', 'facebookexternalhit/1.1', 'Slackbot-LinkExpanding 1.0', 'WhatsApp/2.23']) assert.ok(isPreviewBot(ua), ua); +assert.ok(!isPreviewBot('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0 Safari/537.36')); + +let t = Date.now(); +let page = await (await notePageResponse(req('TelegramBot (like TwitterBot)'), { index: async () => html, threads: slow() })).text(); +assert.match(page, /<title>Adam on Coinos<\/title>/); +assert.match(page, /og:description" content="Moving coins out of old addresses/); +assert.doesNotMatch(page, /og:title" content="Coinos"/); +console.log('✅ the crawler waited', Date.now() - t, 'ms for the post'); + +t = Date.now(); +page = await (await notePageResponse(req('Mozilla/5.0 (X11; Linux x86_64) Chrome/131.0'), { index: async () => html, threads: slow() })).text(); +assert.ok(Date.now() - t < 1000, 'a browser is not held up'); +assert.match(page, /<title>Coinos<\/title>/); +console.log('✅ a browser gets the page on time', Date.now() - t, 'ms'); |
