Files
Alexis Aguilar d1dcb57bdf feat(www): use the shared AiTools component on www pages (#52186)
## Problem

Docs guides, docs troubleshooting pages, and knowledge base guides
render the shared `AiTools` component from `ui-patterns`. The marketing
site renders its own copy of the same actions in `MarkdownActions`, with
the same styles and links. A change to one doesn't reach the other.

Resolves
[DOCS-1505](https://linear.app/supabase/issue/DOCS-1505/use-the-shared-aitools-component-on-www-pages).

## Solution

Blog posts, customer stories, event pages, changelog entries, and
pricing render `AiTools` through a www wrapper, and `MarkdownActions` is
deleted. The wrapper sends `copy_as_markdown_clicked` and
`ask_ai_clicked` with each page's type, as `MarkdownActions` did.

- **Prefer on Google:** blog posts show the Prefer on Google link
through `AiTools`, and clicks send `preferred_source_clicked`. #52026
proposed adding the link through `MarkdownActions`. This PR adds it
through `AiTools` instead, and #52026 is closed. The link's URL is a
shared constant in `markdown-affordance.ts`, which the docs wrapper also
uses.
- **Horizontal layout:** `AiTools` has an `orientation` prop. Pricing
uses it to keep the actions in a row under the hero. The design system's
AI Tools page documents it.
- **Headings:** `AiTools` adds an "AI tools" heading:
  - Blog posts style it like the sidebar's On this page label.
- Pricing, customer stories, and event pages hide it visually, so they
look as they do on the live site. Screen readers still announce it as
the section's label.
- Changelog entries give AI tools its own sidebar section, like Change
type and Products. The Links section appears only when an entry links to
a GitHub discussion.

The changelog index keeps `ChangelogLlmMarkdownButton`. It's a split
button in the header toolbar, and `AiTools` is a list of links built for
sidebars.

## Preview links

Compare the before and afters (since there's a lot of examples here,
links are less visually busy than images in this case):

| Site | Live | Preview |
| ------------- |
--------------------------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| WWW |
[/blog/give-your-supabase-app-its-own-mcp-server](https://supabase.com/blog/give-your-supabase-app-its-own-mcp-server)
|
[/blog/give-your-supabase-app-its-own-mcp-server](https://zone-www-dot-com-git-alexisa-docs-1505-supabase.vercel.app/blog/give-your-supabase-app-its-own-mcp-server)
|
| WWW | [/pricing](https://supabase.com/pricing) |
[/pricing](https://zone-www-dot-com-git-alexisa-docs-1505-supabase.vercel.app/pricing)
|
| WWW | [/customers/berriai](https://supabase.com/customers/berriai) |
[/customers/berriai](https://zone-www-dot-com-git-alexisa-docs-1505-supabase.vercel.app/customers/berriai)
|
| WWW |
[/events/agency-webinar-ai-prototyping-production](https://supabase.com/events/agency-webinar-ai-prototyping-production)
|
[/events/agency-webinar-ai-prototyping-production](https://zone-www-dot-com-git-alexisa-docs-1505-supabase.vercel.app/events/agency-webinar-ai-prototyping-production)
|
| WWW |
[/changelog/cbc-tls-ciphers-deprecated](https://supabase.com/changelog/cbc-tls-ciphers-deprecated)
|
[/changelog/cbc-tls-ciphers-deprecated](https://zone-www-dot-com-git-alexisa-docs-1505-supabase.vercel.app/changelog/cbc-tls-ciphers-deprecated)
|
| WWW |
[/changelog/17817-pgbouncer-and-ipv4-deprecation](https://supabase.com/changelog/17817-pgbouncer-and-ipv4-deprecation)
|
[/changelog/17817-pgbouncer-and-ipv4-deprecation](https://zone-www-dot-com-git-alexisa-docs-1505-supabase.vercel.app/changelog/17817-pgbouncer-and-ipv4-deprecation)
|
| Design system |
[/design-system/docs/fragments/ai-tools](https://supabase.com/design-system/docs/fragments/ai-tools)
|
[/design-system/docs/fragments/ai-tools](https://design-system-git-alexisa-docs-1505-supabase.vercel.app/design-system/docs/fragments/ai-tools)
|

## Review instructions

1. Open each live and preview link side by side.
2. On pricing, check that the actions sit in the same row under the
hero.
3. On the blog post, check that the "AI tools" heading matches the On
this page label.
4. On the blog post, check that Prefer on Google appears in the sidebar
and at the end of the post on mobile.
5. On both changelog entries, check that AI tools has its own sidebar
section. Links appears only on the pgbouncer entry, which links to a
GitHub discussion.
6. On each page, click Copy as Markdown, Ask ChatGPT, and Ask Claude. On
the blog post, also click Prefer on Google. In the browser's network
tab, check that each telemetry request includes the page's `pageType`.
7. On the design system page, check the Horizontal layout example.

## Checklist

Check all before review:

- [x] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [ ] If I wrote a new docs topic or edited an existing topic, I used
the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs
[style
guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
2026-10-27 18:35:40 -04:00

326 lines
13 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import dayjs from 'dayjs'
import Image from 'next/image'
import Link from 'next/link'
import type { PostReturnType, ProcessedBlogData, StaticAuthor, Tag } from 'types/post'
import { Badge, cn } from 'ui'
import { CTASection } from '../CTASection'
import SectionContainerWithCn from '../Layouts/SectionContainerWithCn'
import { AiTools } from '@/components/AiTools'
import { BlogTableOfContents } from '@/components/Blog/BlogTableOfContents'
import DraftModeBanner from '@/components/Blog/DraftModeBanner'
import ShareArticleActions from '@/components/Blog/ShareArticleActions'
import BlogLinks from '@/components/LaunchWeek/7/BlogLinks'
import LW11Summary from '@/components/LaunchWeek/11/LW11Summary'
import LW12Summary from '@/components/LaunchWeek/12/LWSummary'
import LW13Summary from '@/components/LaunchWeek/13/Releases/LWSummary'
import LW14Summary from '@/components/LaunchWeek/14/Releases/LWSummary'
import LW15Summary from '@/components/LaunchWeek/15/LWSummary'
import LWXSummary from '@/components/LaunchWeek/X/LWXSummary'
import { getBlogThumbnailImage } from '@/lib/blog-images'
import { compileBlogMdx } from '@/lib/mdx/compileBlogMdx'
import mdxComponents from '@/lib/mdx/mdxComponents'
type NextCardProps = {
post: { path: string; title: string; formattedDate: string }
label: string
className?: string
}
const NextCard = (props: NextCardProps) => {
const { post, label, className } = props
return (
<Link href={`${post.path}`} as={`${post.path}`}>
<div className={className ?? ''}>
<div className="hover:bg-control cursor-pointer rounded-sm border p-6 transition">
<div className="space-y-4">
<div>
<p className="text-foreground-lighter text-sm">{label}</p>
</div>
<div className="flex flex-col gap-2">
{'title' in post && (
<h4 className="text-foreground text-lg text-balance">
{(post as { title?: string }).title}
</h4>
)}
{'formattedDate' in post && (
<p className="small">{(post as { formattedDate?: string }).formattedDate}</p>
)}
</div>
</div>
</div>
</div>
</Link>
)
}
const BlogPostRenderer = async ({
blog,
blogMetaData,
isDraftMode,
prevPost,
nextPost,
authors,
}: {
blog: ProcessedBlogData
blogMetaData: ProcessedBlogData
isDraftMode: boolean
prevPost?: PostReturnType | null
nextPost?: PostReturnType | null
authors: Array<StaticAuthor>
}) => {
const mdxRendered = await compileBlogMdx(blog.content as string, mdxComponents('blog'))
const isLaunchWeek7 = blogMetaData.launchweek === '7'
const isLaunchWeekX = blogMetaData.launchweek?.toString().toLocaleLowerCase() === 'x'
const isGAWeek = blogMetaData.launchweek?.toString().toLocaleLowerCase() === '11'
const isLaunchWeek12 = blogMetaData.launchweek?.toString().toLocaleLowerCase() === '12'
const isLaunchWeek13 = blogMetaData.launchweek?.toString().toLocaleLowerCase() === '13'
const isLaunchWeek14 = blogMetaData.launchweek?.toString().toLocaleLowerCase() === '14'
const isLaunchWeek15 = blogMetaData.launchweek?.toString().toLocaleLowerCase() === '15'
type TocJsonItem = { content: string; slug: string; lvl: number }
const rawToc = blogMetaData.toc as unknown as { json?: TocJsonItem[] } | string | undefined
const tocItems =
rawToc && typeof rawToc !== 'string' && Array.isArray(rawToc.json)
? rawToc.json.map((h) => ({ title: h.content, url: `#${h.slug}`, depth: h.lvl }))
: []
const toc = tocItems.length > 0 ? <BlogTableOfContents items={tocItems} /> : null
const imageUrl = getBlogThumbnailImage(blogMetaData, {
fallbackToPlaceholder: false,
})
const MARGIN_BOTTOM_CN = 'mb-12'
return (
<>
{isDraftMode && <DraftModeBanner />}
<div className="overflow-x-clip">
<SectionContainerWithCn height="none">
{/*
* Outer grid: back button | main container
*
* base/md : [back:1–12] stacked above [main:1–12]
* lg : [back:1–12] stacked above [main:2–12]
* xl : [back:1–2] alongside [main:3–12]
*/}
<div className="flex justify-center lg:grid grid-cols-12 gap-x-8">
{/* Main container — indented 1 col at lg, alongside back button at xl */}
<div className="min-w-0 w-full max-w-[65ch] lg:max-w-none col-span-12 lg:col-start-2 lg:col-span-10 xl:col-start-2 xl:col-span-11">
{/* Article header — spans the full main container width */}
<div className="py-8 md:py-12 space-y-4">
<div className="flex items-center gap-1.5 text-foreground-lighter text-sm">
<Link
href="/blog"
className="hover:text-foreground inline-flex items-center transition"
>
Blog
</Link>
{blogMetaData.categories && (
<>
<span className="text-foreground-muted"> / </span>
<Link
href={`/blog/categories/${blogMetaData.categories[0]}`}
className="capitalize hover:text-foreground"
>
{blogMetaData.categories[0]}
</Link>
</>
)}
</div>
<h1 className="text-2xl sm:text-3xl lg:text-4xl max-w-3xl text-pretty">
{blogMetaData.title}
</h1>
<div className="flex items-center gap-2">
<div className="text-foreground-lighter flex space-x-3 text-sm">
<p>{dayjs(blogMetaData.date).format('D MMM YYYY')}</p>
<p>·</p>
<p>{(blogMetaData as any).readingTime}</p>
</div>
</div>
{authors.length > 0 && (
<div className="flex flex-row flex-wrap items-center gap-y-4 gap-x-6 md:gap-x-8 mt-6">
{authors.map((author, i: number) => {
const authorImageUrl = author.author_image_url
const authorId =
(author as any).author_id ||
(author as any).username ||
author.author.toLowerCase().replace(/\s+/g, '_')
return (
<Link
href={`/blog/authors/${authorId}`}
className="cursor-pointer"
key={`author-${i}-${author.author}`}
>
<div className="flex items-center gap-2">
{authorImageUrl && (
<Image
src={authorImageUrl}
className="w-5 h-5 md:w-8 md:h-8 border-default rounded-full border aspect-square object-cover"
alt={`${author.author} avatar`}
width={32}
height={32}
/>
)}
<div className="flex flex-col">
<span className="text-foreground text-sm">{author.author}</span>
<span className="text-foreground-lighter text-xs hidden md:inline-block">
{author.position}
</span>
</div>
</div>
</Link>
)
})}
</div>
)}
</div>
{/*
* Inner grid: article body | sidebar
*
* base/md : single column, sidebar hidden
* lg+ : [body:7fr] [sidebar:3fr]
*/}
<div className="lg:grid lg:grid-cols-12 lg:gap-x-8 xl:gap-x-12">
{/* Article body */}
<div className={cn('col-span-8', MARGIN_BOTTOM_CN)}>
{!blogMetaData.youtubeHero && blogMetaData.imgThumb && imageUrl && (
<div className="hidden lg:block relative w-full aspect-[1.91/1] overflow-hidden rounded-lg border border-foreground/10 mb-6">
<Image
src={imageUrl}
alt={blogMetaData.title}
fill
quality={100}
sizes="(max-width: 768px) 100vw, 58vw"
className="object-cover"
/>
</div>
)}
<article>
<div className="prose prose-docs wrap-break-word">
{blogMetaData.youtubeHero ? (
<iframe
title="YouTube video player"
className="w-full"
width="700"
height="350"
src={blogMetaData.youtubeHero}
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
allowFullScreen={true}
/>
) : null}
{mdxRendered}
</div>
</article>
{isLaunchWeek7 && <BlogLinks />}
{isLaunchWeekX && <LWXSummary />}
{isGAWeek && <LW11Summary />}
{isLaunchWeek12 && <LW12Summary />}
{isLaunchWeek13 && <LW13Summary />}
{isLaunchWeek14 && <LW14Summary />}
{isLaunchWeek15 && <LW15Summary />}
<div className="lg:hidden py-8 flex flex-col gap-6">
<AiTools
pagePath={`/blog/${blogMetaData.slug}`}
pageType="blog"
showPreferredSource
titleClassName="text-foreground tracking-wide font-normal"
/>
<ShareArticleActions title={blogMetaData.title} slug={blogMetaData.slug} />
</div>
<div className="grid gap-8 mt-8 lg:grid-cols-1">
<div>
{prevPost && (
<NextCard
post={
prevPost as unknown as {
path: string
title: string
formattedDate: string
}
}
label="Previous post"
/>
)}
</div>
<div>
{nextPost && (
<NextCard
post={
nextPost as unknown as {
path: string
title: string
formattedDate: string
}
}
label="Next post"
className="text-right"
/>
)}
</div>
</div>
</div>
{/* Sidebar — only above lg */}
<div
className={cn(
'hidden lg:block col-span-4 col-start-9 space-y-8 lg:pl-6',
MARGIN_BOTTOM_CN
)}
>
{(blogMetaData.tags as Tag[])?.length > 0 && (
<div className="flex flex-wrap items-center gap-2">
{(blogMetaData.tags as Tag[])?.map((tag) => {
const tagName = typeof tag === 'string' ? tag : tag.name
const tagId = typeof tag === 'string' ? tag : tag.id.toString()
return (
<Link
className="flex"
href={`/blog/tags/${tagName}`}
key={`category-badge-${tagId}`}
>
<Badge>{tagName}</Badge>
</Link>
)
})}
</div>
)}
<div className="sticky top-24 flex flex-col gap-6 max-h-[calc(100vh-7rem)]">
<p className="text-foreground font-mono uppercase tracking-wide text-xs -mb-2">
On this page
</p>
<div className="overflow-y-auto min-h-0 flex-1">{toc}</div>
<div className="shrink-0 flex flex-col gap-6">
<AiTools
pagePath={`/blog/${blogMetaData.slug}`}
pageType="blog"
showPreferredSource
titleClassName="text-foreground tracking-wide font-normal"
/>
<ShareArticleActions title={blogMetaData.title} slug={blogMetaData.slug} />
</div>
</div>
</div>
</div>
</div>
</div>
</SectionContainerWithCn>
<div className="border-t">
<CTASection />
</div>
</div>
</>
)
}
export default BlogPostRenderer