Can we improve our image embeds

merged…
osebo51d ago

See screenshot, improve all cases

IMG_8314.jpeg
IMG_8314.jpeg
3 repliesoldestnewest
Osebotfable-5-151d ago

The screenshot is Discord unfurling three different URLs — a thread, the home page and a /join/… invite — and every one shows the same generic card ("Evenings / Post a task. Claude replies in the thread."). Two reasons:

  1. The only metadata in the app is the static metadata in app/layout.tsx; no page sets its own title/description and there is no og:image at all.
  2. Every page calls requireUser(), which 307-redirects anonymous visitors to /signin. Discord's crawler is anonymous, so even if a thread page had generateMetadata, the crawler would never see it — it lands on /signin and reads the layout defaults.

Plan:

  • Root: metadataBase, title template %s · Evenings, openGraph.siteName, twitter.card = summary_large_image, and a generated app/opengraph-image.tsx (next/og) so the home/sign-in link gets a proper branded card.
  • Thread /threads/[id]: generateMetadata → title = thread title, description = "workspace · by @login · N replies · status" + a short plain-text excerpt of the opening post; dynamic opengraph-image.tsx rendering title / workspace / status.
  • Workspace /workspaces/[id]: generateMetadata (name, member + thread counts) + OG image.
  • Join /join/[token]: "Join <workspace> on Evenings" title/description + OG image; signed-in flow (auto-join → redirect) unchanged.
  • Anonymous visitors to those three routes get a small 200 "sign in to read" landing card (with the thread/workspace title and a Sign in button that returns them to the same URL) instead of the 307, so crawlers can read the metadata. / and everything else keep redirecting as today.

Note the deliberate trade-off: thread titles, workspace names and a short excerpt become visible to anyone holding the (unguessable UUID) link, not just signed-in users — that's inherent to rich unfurls. Repo names and post bodies beyond the excerpt stay behind sign-in. Shout if you'd rather keep excerpts out.

Osebotfable-5-151d ago

Implementation is committed on thread/3785c1d6 (f4ba9a5) and next build + tsc pass. What changed:

  • lib/site.ts — SITE_NAME, TAGLINE, siteUrl() (SITE_URL → Vercel prod/branch URL → localhost), excerpt() (markdown → plain text, ~160 chars).
  • lib/previews.ts — cache()'d public-safe summaries: threadPreview, workspacePreview, invitePreview + describe*() one-liners shared by metadata and the gate.
  • lib/og.tsx — shared 1200×630 card (parchment bg, white card, uppercase kicker, clamped title, meta line, outlined status badge) via next/og.
  • app/opengraph-image.tsx (default), app/threads/[id]/opengraph-image.tsx, app/workspaces/[id]/opengraph-image.tsx, app/join/[token]/opengraph-image.tsx.
  • generateMetadata on thread / workspace / join pages; root layout gets metadataBase, title template %s · Evenings, og:site_name, twitter:card=summary_large_image.
  • components/sign-in-gate.tsx — the 200 landing card anonymous visitors (and crawlers) get on those three routes instead of the 307.

Rendered cards attached below. Now spinning up a local Postgres in the sandbox to curl the real <head> of an anonymous /threads/:id request and confirm it's a 200 with the right tags.

Osebotfable-5-151d agothreadide@bac4a78

Pushed to thread/3785c1d6 (threadide @ bac4a78, two commits). No PR opened yet — say the word and I'll open one.

What was wrong

Discord (and any other unfurler) showed the same "Evenings / Post a task…" card for every URL because:

  1. The only metadata in the app was the static block in app/layout.tsx; no page had its own title/description and there was no og:image anywhere.
  2. requireUser() 307-redirects anonymous requests to /signin. Crawlers are anonymous, so even a page with perfect metadata would never have been seen — they got the sign-in page's defaults.

What changed

URLBeforeNow
/threads/:idgeneric cardtitle = thread title; description = workspace · by @login · N replies · status — <excerpt of opening post>; generated 1200×630 card with status badge
/workspaces/:idgeneric cardworkspace name, N members · M threads; generated card
/join/:tokengeneric card"Join <workspace>", @owner invited you to join … — N members, M threads. Sign in with GitHub to accept.; generated card with INVITE badge
/, /signin, everything elsegeneric card, no imagesame title/tagline but now with og:site_name, twitter:card=summary_large_image and a branded default og:image
  • Anonymous visitors to the three shareable routes get a 200 landing card (components/sign-in-gate.tsx: kicker, title, the same one-line description, "Sign in with GitHub to read/join" that returns to the same URL) instead of being bounced to /signin. That's what lets crawlers read the metadata. Every other page still redirects exactly as before; signed-in behaviour is unchanged (join still auto-joins and redirects).
  • lib/previews.ts — cache()'d, public-safe summaries used by page + metadata + image (one query per request). Deliberately exposes only title, author login, counts, status and a ~160-char plain-text excerpt. Not exposed: repo names, member lists, branch, post bodies.
  • lib/og.tsx — shared card renderer (next/og), themed like the site (parchment bg, flat white card, uppercase kicker, clamped title that scales down for long titles, outlined status badge). Kicker dedupes when a workspace is named "Evenings".
  • lib/site.ts — SITE_NAME, TAGLINE, siteUrl() for metadataBase (uses SITE_URL/NEXT_PUBLIC_SITE_URL if set, else Vercel's production/branch URL), excerpt(), previewMetadata().
  • Root layout: metadataBase, title template %s · Evenings, openGraph.siteName, twitter.card. Sign-in page heading fixed from "Thread IDE" → Evenings.

Verified

Ran the production build against a local Postgres in the sandbox with seeded rows and curled as an anonymous client: /threads/:id → 200 with og:title, og:description, og:site_name, og:type=article, absolute og:image, twitter:card=summary_large_image; /join/:token and /workspaces/:id likewise; /opengraph-image and the per-thread image → 200 image/png; / → 307 to /signin as before; unknown thread → 404; revoked invite → "Invite link expired". tsc and next build clean.

Gotcha found on the way: Next shallow-merges metadata per top-level key, so a page that sets openGraph: {title} silently drops the layout's siteName, and setting twitter: {title} reverts the card to summary (thumbnail instead of big image in Discord). previewMetadata() builds the full object so this can't regress — use it for any new shareable page.

Trade-off to be aware of

Thread titles, workspace names and a short excerpt of the opening post are now visible to anyone holding the (unguessable UUID / token) link without signing in — that's inherent to rich previews. If you'd rather drop the excerpt, it's one line in describeThread(). Discord caches unfurls, so already-posted links may keep the old card until re-shared.

Optional follow-ups: set SITE_URL=https://threadide.vercel.app in Vercel env if the project ever moves domains (today the Vercel-provided vars resolve it fine); a serif font for the card would need a bundled .ttf (satori only ships Noto Sans).

og:image for a thread link (title, workspace kicker deduped against site name, author + replies, status badge)
og:image for a thread link (title, workspace kicker deduped against site name, author + replies, status badge)
og:image for a /join/… invite link
og:image for a /join/… invite link
What an anonymous visitor sees on /threads/:id now (390px) instead of being bounced to /signin
What an anonymous visitor sees on /threads/:id now (390px) instead of being bounced to /signin
Diff · 14 files
diff --git a/threadide/app/layout.tsx b/threadide/app/layout.tsx
--- a/threadide/app/layout.tsx
+++ b/threadide/app/layout.tsx
@@ -4,10 +4,21 @@ import "./globals.css";
 import { currentUser } from "@/lib/session";
 import { UserMenu } from "@/components/user-menu";
 import { SiteNav } from "@/components/site-nav";
+import { SITE_NAME, TAGLINE, siteUrl } from "@/lib/site";
 
+/**
+ * Site-wide defaults for link previews. Pages override title/description via generateMetadata
+ * (threads, workspaces, invites) and the opengraph-image.tsx files beside them supply og:image;
+ * app/opengraph-image.tsx covers everything else. metadataBase makes those image URLs absolute,
+ * which crawlers require.
+ */
 export const metadata: Metadata = {
-  title: "Evenings",
-  description: "Post a task. Claude replies in the thread.",
+  metadataBase: new URL(siteUrl()),
+  title: { default: SITE_NAME, template: `%s · ${SITE_NAME}` },
+  description: TAGLINE,
+  applicationName: SITE_NAME,
+  openGraph: { siteName: SITE_NAME, type: "website", locale: "en_US" },
+  twitter: { card: "summary_large_image" },
 };
diff --git a/threadide/app/threads/[id]/page.tsx b/threadide/app/threads/[id]/page.tsx
--- a/threadide/app/threads/[id]/page.tsx
+++ b/threadide/app/threads/[id]/page.tsx
@@ -7,11 +8,22 @@
-import { membership, requireUser } from "@/lib/session";
+import { currentUser, membership } from "@/lib/session";
 import { DeleteThreadButton } from "@/components/delete-thread";
+import { SignInGate } from "@/components/sign-in-gate";
+import { describeThread, threadPreview } from "@/lib/previews";
+import { previewMetadata } from "@/lib/site";
 
 export const dynamic = "force-dynamic";
 
+/** Link previews (Discord, Slack, iMessage…): thread title, where it lives, who asked, and a short excerpt. */
+export async function generateMetadata({ params }: { params: Promise<{ id: string }> }): Promise<Metadata> {
+  const { id } = await params;
+  const t = await threadPreview(id);
+  if (!t) return { title: "Thread not found", robots: { index: false } };
+  return previewMetadata(t.title, describeThread(t), { type: "article", publishedTime: t.createdAt.toISOString(), modifiedTime: t.updatedAt.toISOString() });
+}
@@ -21,7 +33,14 @@ export default async function ThreadPage({
   const { id } = await params;
   const order = (await searchParams).order === "oldest" ? "oldest" : "newest";
-  const user = await requireUser(`/threads/${id}`);
+  const user = await currentUser();
+  if (!user) {
+    // Anonymous: a 200 landing card instead of a redirect, so crawlers get the metadata above
+    // and humans get a one-click sign-in that returns here.
+    const t = await threadPreview(id);
+    if (!t) notFound();
+    return <SignInGate kicker={t.workspace ? `Thread in ${t.workspace.name}` : "General discussion thread"} title={t.title} description={describeThread(t)} next={`/threads/${id}`} />;
+  }
   const thread = await getThread(id);
   if (!thread) notFound();
diff --git a/threadide/app/threads/[id]/opengraph-image.tsx b/threadide/app/threads/[id]/opengraph-image.tsx
new file mode 100644
--- /dev/null
+++ b/threadide/app/threads/[id]/opengraph-image.tsx
@@ -0,0 +1,16 @@
+import { ogCard, ogContentType, ogSize } from "@/lib/og";
+import { threadPreview } from "@/lib/previews";
+import { plural, statusLabel, TAGLINE } from "@/lib/site";
+
+// Public, unauthenticated by design: this is what Discord/Slack/iMessage fetch for a thread link.
+export const alt = "Thread preview";
+export const size = ogSize;
+export const contentType = ogContentType;
+
+export default async function Image({ params }: { params: Promise<{ id: string }> }) {
+  const { id } = await params;
+  const t = await threadPreview(id);
+  if (!t) return ogCard({ title: "Thread not found", meta: TAGLINE });
+  const meta = [t.authorLogin ? `by @${t.authorLogin}` : null, plural(t.replyCount, "reply", "replies")].filter(Boolean).join(" · ");
+  return ogCard({ kicker: t.workspace?.name ?? "general discussion", title: t.title, meta, badge: statusLabel(t.status) });
+}
diff --git a/threadide/components/sign-in-gate.tsx b/threadide/components/sign-in-gate.tsx
new file mode 100644
--- /dev/null
+++ b/threadide/components/sign-in-gate.tsx
@@ -0,0 +1,26 @@
+import { signIn } from "@/auth";
+
+/**
+ * What anonymous visitors see on a thread / workspace / invite URL instead of a 307 to /signin.
+ * Serving a 200 here is what lets link crawlers (Discord, Slack, iMessage…) read the page's
+ * generateMetadata — a redirect would hand them the generic sign-in page. The copy says only
+ * what the preview already reveals (title + counts); the real content needs a session.
+ * `next` is where to land after GitHub sign-in: the same URL.
+ */
+export function SignInGate({ kicker, title, description, next, cta = "Sign in with GitHub to read" }: { kicker: string; title: string; description?: string; next: string; cta?: string }) {
+  return (
+    <div className="card sign-in-gate">
+      <div className="muted gate-kicker">{kicker}</div>
+      <h2>{title}</h2>
+      {description && <p className="muted">{description}</p>}
+      <form
+        action={async () => {
+          "use server";
+          await signIn("github", { redirectTo: next });
+        }}
+      >
+        <button>{cta}</button>
+      </form>
+    </div>
+  );
+}
diff --git a/threadide/lib/site.ts b/threadide/lib/site.ts
new file mode 100644
--- /dev/null
+++ b/threadide/lib/site.ts
@@ -0,0 +1,70 @@
+import type { Metadata } from "next";
+
+export const SITE_NAME = "Evenings";
+export const TAGLINE = "Post a task. Claude replies in the thread. Your team reads along.";
+
+/** Absolute origin for metadataBase: SITE_URL → Vercel prod/branch URL → localhost. */
+export function siteUrl(): string {
+  const explicit = process.env.NEXT_PUBLIC_SITE_URL ?? process.env.SITE_URL;
+  if (explicit) return explicit.replace(/\/$/, "");
+  if (process.env.VERCEL_ENV === "production" && process.env.VERCEL_PROJECT_PRODUCTION_URL) return `https://${process.env.VERCEL_PROJECT_PRODUCTION_URL}`;
+  const vercel = process.env.VERCEL_BRANCH_URL ?? process.env.VERCEL_URL;
+  if (vercel) return `https://${vercel}`;
+  return `http://localhost:${process.env.PORT ?? 3000}`;
+}
+
+/** First `max` chars of a markdown post as plain text (code blocks, images, markup stripped). */
+export function excerpt(markdown: string, max = 160): string { /* … */ }
+
+/**
+ * Metadata for a shareable page. Next.js shallow-merges metadata per top-level key, so a page
+ * that sets `openGraph` or `twitter` at all loses the layout's siteName / card type — build the
+ * whole object here instead of in each page.
+ */
+export function previewMetadata(title: string, description: string, og: { type?: "website" | "article"; publishedTime?: string; modifiedTime?: string } = {}): Metadata {
+  const { type = "website", ...times } = og;
+  return {
+    title,
+    description,
+    robots: { index: false },
+    openGraph: type === "article" ? { title, description, siteName: SITE_NAME, locale: "en_US", type, ...times } : { title, description, siteName: SITE_NAME, locale: "en_US", type },
+    twitter: { card: "summary_large_image", title, description },
+  };
+}