Skip to content

Add share redirect page with OG meta tags and thumbnail generation#2156

Open
gary149 wants to merge 10 commits intomainfrom
claude/custom-conversation-thumbnails-WZNK0
Open

Add share redirect page with OG meta tags and thumbnail generation#2156
gary149 wants to merge 10 commits intomainfrom
claude/custom-conversation-thumbnails-WZNK0

Conversation

@gary149
Copy link
Collaborator

@gary149 gary149 commented Feb 26, 2026

Summary

This PR adds a new share redirect page (/r/[id]) that handles conversation sharing with proper Open Graph meta tags for social media previews and dynamic thumbnail generation.

Key Changes

  • New share redirect route (src/routes/r/[id]/+page.svelte):

    • Renders OG meta tags for social media sharing (title, description, image, etc.)
    • Handles client-side redirect logic with fallback to view-only mode
    • Shows loading state while processing the share import
  • Server-side data loading (src/routes/r/[id]/+page.server.ts):

    • Fetches shared conversation metadata (title, model)
    • Constructs OG image URL pointing to dynamic thumbnail endpoint
    • Passes share data to the page for meta tag rendering
  • Dynamic thumbnail generation (src/routes/r/[id]/thumbnail.png/+server.ts):

    • Generates PNG thumbnails on-demand using Satori and Resvg
    • Renders conversation title and model name with HuggingChat branding
    • Implements caching headers (24h client-side, 7d server-side with stale-while-revalidate)
  • Thumbnail component (src/routes/r/[id]/thumbnail.png/ConversationThumbnail.svelte):

    • Svelte component for thumbnail layout (1200x648px)
    • Includes chat bubble icon, title truncation, model name, and branding
    • Styled with gradient background and responsive typography
  • Updated page load logic (src/routes/r/[id]/+page.ts):

    • Defers client-side redirect to +page.svelte's onMount to allow SSR rendering of OG tags
    • Preserves existing import logic for authenticated users
    • Falls back to view-only mode for unauthenticated users
  • Layout adjustment (src/routes/+layout.svelte):

    • Excludes /r/ routes from default meta tags to prevent conflicts with share-specific OG tags

Implementation Details

  • SSR-friendly: OG meta tags are rendered server-side for crawler compatibility while client-side redirect happens after
  • Graceful fallback: If share import fails for logged-in users, falls back to view-only mode
  • Thumbnail caching: Aggressive caching strategy with stale-while-revalidate for performance
  • Title truncation: Manual truncation in thumbnail component for predictable Satori rendering

https://claude.ai/code/session_01TWxkFGJP7HbWyUHpBwx26N

Shared conversation URLs (/r/[id]) now generate dynamic thumbnails
showing the conversation topic, so social media previews display
meaningful content instead of the generic HuggingChat image.

- Add thumbnail.png endpoint using Satori+Resvg (same as model thumbnails)
- Convert /r/[id] from redirect-only to SSR page with OG meta tags
- Redirect logic moved to client-side onMount (crawlers see OG tags)
- Exclude /r/ paths from layout default OG tags to prevent duplicates

https://claude.ai/code/session_01TWxkFGJP7HbWyUHpBwx26N
Copy link

@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: e996b3c009

ℹ️ 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".

<!-- use those meta tags everywhere except on special listing pages -->
<!-- feel free to refacto if there's a better way -->
{#if !page.url.pathname.includes("/models/")}
{#if !page.url.pathname.includes("/models/") && !page.url.pathname.startsWith("/r/")}

Choose a reason for hiding this comment

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

P2 Badge Make /r/ meta-tag exclusion base-path aware

I checked svelte.config.js and kit.paths.base is configurable via APP_BASE, so page.url.pathname can be prefixed (for example /chat/r/<id>). With the current pathname.startsWith('/r/') guard, those deployments won't skip the default OG/Twitter tags, so /r/[id] pages render both global and share-specific metadata and crawlers may pick the wrong preview title/image.

Useful? React with 👍 / 👎.

Use `${base}/r/` instead of hardcoded `/r/` so deployments with
a custom APP_BASE path correctly skip default OG tags on share pages.
The thumbnail was only served on /r/[id] but users land on
/conversation/[id] after redirect, so sharing that URL had no
custom OG preview. Now shared conversations render OG meta tags
on the conversation page too, pointing to /r/[id]/thumbnail.png.
Also exclude shared conversations from layout default OG tags.
- Return 404 instead of rendering an expensive fallback thumbnail
  when the shared conversation doesn't exist (prevents CPU exhaustion
  from random ID requests)
- Use fromShare query param for OG image URL on imported conversations
  so the thumbnail points to the correct /r/{shareId}/thumbnail.png
  instead of /r/{objectId}/thumbnail.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants