Skip to content

Render URL-only notes as rich link previews#27

Open
bclinkinbeard wants to merge 2 commits intomainfrom
codex/display-url-notes-with-summaries
Open

Render URL-only notes as rich link previews#27
bclinkinbeard wants to merge 2 commits intomainfrom
codex/display-url-notes-with-summaries

Conversation

@bclinkinbeard
Copy link
Copy Markdown
Owner

Motivation

  • Notes that are just a single URL should be more useful and scannable by showing page metadata instead of raw links.
  • Tweet/X links should be shown with a Twitter-style card so social posts are easier to identify at a glance.

Description

  • Detect single http(s) URL notes on the client and render a preview block instead of plain transcription by adding extractSingleUrl, createUrlPreviewElement, ensureLinkPreview, and related logic in app.js and wiring it into the note card rendering flow.
  • Add in-memory linkPreviewCache and linkPreviewInflight with loadLinkPreview to deduplicate in-flight requests and avoid duplicate network calls.
  • Add a new server endpoint GET /api/link-preview (api/link-preview.js) that normalizes/validates URLs, fetches Open Graph/Twitter meta for general pages, and uses Twitter oEmbed for tweet/status URLs to return a normalized preview payload.
  • Add styles for generic link previews and tweet/X cards in app.css (classes: .link-preview, .link-preview-title, .link-preview-excerpt, .link-preview-meta, .tweet-preview).

Testing

  • Ran the project test suite via npm test, which completed successfully and reported all tests passing (297/297 tests passed and node/JS tests all OK).

Codex Task

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 31, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
voice-notes Ready Ready Preview Apr 1, 2026 1:29pm

Request Review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d0dff438d3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread api/link-preview.js
Comment on lines +15 to +19
if (!['http:', 'https:'].includes(parsed.protocol)) {
return null;
}

return parsed.toString();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reject private/internal URLs before fetching previews

normalizeUrl only enforces http(s) and then GET passes the result directly into buildWebPreview, so callers can request previews for hosts like localhost, RFC1918 ranges, or cloud metadata IPs. In any deployment where this function has internal network reachability, this creates an SSRF path that can probe or exfiltrate internal services. Add host/IP validation (including DNS resolution checks) before allowing server-side fetches.

Useful? React with 👍 / 👎.

Comment thread api/link-preview.js
Comment on lines +80 to +82
} finally {
clearTimeout(timeout);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep request timeout active while reading response body

The timeout is cleared as soon as fetch() returns a Response, but buildWebPreview then calls response.text() afterward. Since fetch resolves on headers, a target can send headers quickly and then stall/stream the body indefinitely, tying up the function until platform hard timeouts. Keep the abort timer active through body consumption (or enforce a body-size/read-time limit).

Useful? React with 👍 / 👎.

Comment thread app.js
Comment on lines +1112 to +1115
.catch(() => null)
.then((preview) => {
linkPreviewCache.set(url, preview);
linkPreviewInflight.delete(url);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not cache failed preview lookups as completed

On any fetch/parsing error, loadLinkPreview converts the failure to null and stores that null in linkPreviewCache. ensureLinkPreview then sees the URL as cached and never retries, so transient failures permanently leave the card in a "Loading preview…" state until reload. Failed fetches should be retried (or cached with a short TTL/error state) instead of treated as a successful permanent result.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 88adb20ea5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread api/link-preview.js

function findMetaContent(html, selectors) {
for (const selector of selectors) {
const regex = new RegExp(`<meta[^>]+${selector}[^>]+content=["']([^"']+)["'][^>]*>`, 'i');
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Parse meta tags regardless of attr order and apostrophes

The metadata extractor regex assumes the selected attribute appears before content and that the content value contains neither quote type (([^"']+)). In practice many pages emit tags like <meta content="..." property="og:description">, and descriptions often include apostrophes (e.g., Today's), so this code misses or truncates valid OG/Twitter metadata and produces degraded previews even when tags are present. Please make parsing attribute-order-independent and allow the opposite quote character inside quoted values.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant