Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

feat(docsite): add social share metadata (OpenGraph + Twitter cards) (#3018)

Cindy Zhang30eb1dea0bf9
diff --git a/apps/docsite/src/app/blog/[slug]/page.tsx b/apps/docsite/src/app/blog/[slug]/page.tsx
index 0d7300c566..8fd9a3a0fe 100644
--- a/apps/docsite/src/app/blog/[slug]/page.tsx
+++ b/apps/docsite/src/app/blog/[slug]/page.tsx
@@ -23,19 +23,34 @@ export async function generateMetadata({
const {slug} = await params;
const post = blogPosts.find(p => p.slug === slug);
if (!post) {
- return {title: 'Blog — Astryx'};
+ return {title: 'Blog'};
}
- const images = post.coverImage ? [{url: post.coverImage}] : undefined;
+ // Use the post's cover image for the social card when present; otherwise
+ // fall back to the branded default card. Next.js shallow-merges metadata —
+ // a route that sets `openGraph`/`twitter` replaces the root object wholesale
+ // (images are not inherited), so the fallback must be explicit here.
+ const ogImage = post.coverImage ?? '/blog-post-01.png';
+ const ogAlt = post.coverImage ? (post.coverAlt ?? post.title) : post.title;
+
return {
- title: `${post.title} — Astryx Blog`,
+ // Renders as "<post title> · Astryx" via the root layout title template.
+ title: post.title,
description: post.description,
openGraph: {
+ type: 'article',
title: post.title,
description: post.description,
- type: 'article',
+ url: `/blog/${post.slug}`,
publishedTime: post.date,
- ...(images ? {images} : {}),
+ ...(post.updatedAt ? {modifiedTime: post.updatedAt} : {}),
+ images: [{url: ogImage, alt: ogAlt}],
+ },
+ twitter: {
+ card: 'summary_large_image',
+ title: post.title,
+ description: post.description,
+ images: [ogImage],
},
};
}
diff --git a/apps/docsite/src/app/blog/page.tsx b/apps/docsite/src/app/blog/page.tsx
index 39839747fd..32d8249c55 100644
--- a/apps/docsite/src/app/blog/page.tsx
+++ b/apps/docsite/src/app/blog/page.tsx
@@ -10,10 +10,30 @@ import type {Metadata} from 'next';
import {blogPosts, blogTypes} from '../../generated/blogRegistry';
import {BlogIndex} from '../../components/blog/BlogIndex';
+const BLOG_TITLE = 'Blog';
+const BLOG_DESCRIPTION =
+ 'Notes on building Astryx — releases, guides, stories, and perspectives on designing a system for humans and agents.';
+
+// Next.js shallow-merges metadata: a child route that declares `openGraph`/
+// `twitter` REPLACES the root object wholesale (images are not inherited), so
+// we re-state the default social image here.
export const metadata: Metadata = {
- title: 'Blog — Astryx',
- description:
- 'Notes on building Astryx — releases, guides, stories, and perspectives on designing a system for humans and agents.',
+ // Renders as "Blog · Astryx" via the root layout title template.
+ title: BLOG_TITLE,
+ description: BLOG_DESCRIPTION,
+ openGraph: {
+ type: 'website',
+ title: `${BLOG_TITLE} · Astryx`,
+ description: BLOG_DESCRIPTION,
+ url: '/blog',
+ images: ['/blog-post-01.png'],
+ },
+ twitter: {
+ card: 'summary_large_image',
+ title: `${BLOG_TITLE} · Astryx`,
+ description: BLOG_DESCRIPTION,
+ images: ['/blog-post-01.png'],
+ },
};
export default function BlogPage() {
diff --git a/apps/docsite/src/app/layout.tsx b/apps/docsite/src/app/layout.tsx
index be52ce9cea..5c1a63b8d0 100644
--- a/apps/docsite/src/app/layout.tsx
+++ b/apps/docsite/src/app/layout.tsx
@@ -12,13 +12,57 @@ import {Providers} from './providers';
// loads via the shared Google Fonts <link> in <head> below, which is the
// "Good" path from the theming wiki §Font Declarations.
+// Public origin for the docsite. Set NEXT_PUBLIC_SITE_URL in other
+// environments (e.g. preview deploys); defaults to the production domain so
+// metadataBase resolves relative OG/Twitter image paths to absolute URLs —
+// social scrapers (Facebook, X, LinkedIn, Slack, iMessage) require absolute
+// image URLs or the card image is dropped.
+const SITE_URL =
+ process.env.NEXT_PUBLIC_SITE_URL ?? 'https://astryx.atmeta.com';
+
+const SITE_NAME = 'Astryx';
+const SITE_TITLE = 'Astryx Design System';
+const SITE_DESCRIPTION =
+ 'An open source design system that is fully customizable and agent ready.';
+
+// Default social card image: the launch banner that the announcement blog post
+// uses for its cover. Reusing the same branded banner keeps the shared-link
+// preview consistent with the launch creative across the site and the post.
+const OG_IMAGE = '/blog-post-01.png';
+
export const metadata: Metadata = {
- title: 'Astryx Design System',
- description:
- 'An open source design system that is fully customizable and agent ready.',
+ metadataBase: new URL(SITE_URL),
+ title: {
+ default: SITE_TITLE,
+ // Per-page `title` values render as "<page> · Astryx".
+ template: `%s · ${SITE_NAME}`,
+ },
+ description: SITE_DESCRIPTION,
+ applicationName: SITE_NAME,
icons: {
icon: '/favicon.svg',
},
+ openGraph: {
+ type: 'website',
+ siteName: SITE_NAME,
+ title: SITE_TITLE,
+ description: SITE_DESCRIPTION,
+ url: '/',
+ images: [
+ {
+ url: OG_IMAGE,
+ width: 1200,
+ height: 675,
+ alt: 'Astryx — an open source design system by Meta',
+ },
+ ],
+ },
+ twitter: {
+ card: 'summary_large_image',
+ title: SITE_TITLE,
+ description: SITE_DESCRIPTION,
+ images: [OG_IMAGE],
+ },
};
export default function RootLayout({children}: {children: React.ReactNode}) {