The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix(www, changelog) - add in canonical URLs for product, blogs, partners, pricing pages (#51859)
Kody Jacksonf15391efeeaa
diff --git a/apps/www/app/(products)/auth/page.tsx b/apps/www/app/(products)/auth/page.tsxindex 6276384f5fb..5d5d0d8125e 100644--- a/apps/www/app/(products)/auth/page.tsx+++ b/apps/www/app/(products)/auth/page.tsx@@ -3,13 +3,17 @@ import type { Metadata } from 'next'import { ApiSection } from './_components/ApiSection'import { AuthContent } from './_components/AuthContent'import { RLSSection } from './_components/RLSSection'+import { canonicalAlternates } from '@/lib/canonical'import { mdAlternates } from '@/lib/md-alternates'export const metadata: Metadata = {title: 'Auth | Supabase',description:'Add user sign ups and logins to your app. Secure your data with Row Level Security. Works with all major OAuth providers.',- alternates: mdAlternates('auth'),+ alternates: {+ ...canonicalAlternates('/auth'),+ ...mdAlternates('auth'),+ },}export default function AuthPage() {diff --git a/apps/www/app/(products)/compute/page.tsx b/apps/www/app/(products)/compute/page.tsxindex b2953776ea0..9ddbd7732aa 100644--- a/apps/www/app/(products)/compute/page.tsx+++ b/apps/www/app/(products)/compute/page.tsx@@ -1,13 +1,17 @@import type { Metadata } from 'next'import { ComputeContent } from './_components/ComputeContent'+import { canonicalAlternates } from '@/lib/canonical'import { mdAlternates } from '@/lib/md-alternates'export const metadata: Metadata = {title: 'Compute | Supabase',description:'Run AI-agent sandboxes and production backends on one runtime, next to your database. Now in Private Alpha.',- alternates: mdAlternates('compute'),+ alternates: {+ ...canonicalAlternates('/compute'),+ ...mdAlternates('compute'),+ },}export default function ComputePage() {diff --git a/apps/www/app/(products)/database/page.tsx b/apps/www/app/(products)/database/page.tsxindex ac1aa4fcafd..906f3821e82 100644--- a/apps/www/app/(products)/database/page.tsx+++ b/apps/www/app/(products)/database/page.tsx@@ -2,13 +2,17 @@ import type { Metadata } from 'next'import { ApiSection } from './_components/ApiSection'import { DatabaseContent } from './_components/DatabaseContent'+import { canonicalAlternates } from '@/lib/canonical'import { mdAlternates } from '@/lib/md-alternates'export const metadata: Metadata = {title: 'Database | Supabase',description:'Every Supabase project is a dedicated Postgres database. Use it on its own, or with the rest of the Supabase platform. 100% portable with no vendor lock-in.',- alternates: mdAlternates('database'),+ alternates: {+ ...canonicalAlternates('/database'),+ ...mdAlternates('database'),+ },}export default function DatabasePage() {diff --git a/apps/www/app/(products)/edge-functions/page.tsx b/apps/www/app/(products)/edge-functions/page.tsxindex 999a635f90e..fed851f9ac2 100644--- a/apps/www/app/(products)/edge-functions/page.tsx+++ b/apps/www/app/(products)/edge-functions/page.tsx@@ -1,12 +1,16 @@import type { Metadata } from 'next'import { EdgeFunctionsContent } from './_components/EdgeFunctionsContent'+import { canonicalAlternates } from '@/lib/canonical'import { mdAlternates } from '@/lib/md-alternates'export const metadata: Metadata = {title: 'Edge Functions | Supabase',description: 'Execute your code closest to your users with fast deploy times and low latency.',- alternates: mdAlternates('edge-functions'),+ alternates: {+ ...canonicalAlternates('/edge-functions'),+ ...mdAlternates('edge-functions'),+ },}export default function EdgeFunctionsPage() {diff --git a/apps/www/app/(products)/realtime/page.tsx b/apps/www/app/(products)/realtime/page.tsxindex fa6be5958ee..89289a90862 100644--- a/apps/www/app/(products)/realtime/page.tsx+++ b/apps/www/app/(products)/realtime/page.tsx@@ -2,13 +2,17 @@ import type { Metadata } from 'next'import { ApiSection } from './_components/ApiSection'import { RealtimeContent } from './_components/RealtimeContent'+import { canonicalAlternates } from '@/lib/canonical'import { mdAlternates } from '@/lib/md-alternates'export const metadata: Metadata = {title: 'Realtime | Supabase',description:'Sync client state globally over WebSockets. Listen to database changes, store user presence, and broadcast messages in real time.',- alternates: mdAlternates('realtime'),+ alternates: {+ ...canonicalAlternates('/realtime'),+ ...mdAlternates('realtime'),+ },}export default function RealtimePage() {diff --git a/apps/www/app/(products)/storage/page.tsx b/apps/www/app/(products)/storage/page.tsxindex 484c72b9707..224459cf519 100644--- a/apps/www/app/(products)/storage/page.tsx+++ b/apps/www/app/(products)/storage/page.tsx@@ -3,13 +3,17 @@ import type { Metadata } from 'next'import { ApiSection } from './_components/ApiSection'import { PermissionsSection } from './_components/PermissionsSection'import { StorageContent } from './_components/StorageContent'+import { canonicalAlternates } from '@/lib/canonical'import { mdAlternates } from '@/lib/md-alternates'export const metadata: Metadata = {title: 'Storage | Supabase',description:'An open source S3 compatible storage solution with unlimited scalability, for any file type.',- alternates: mdAlternates('storage'),+ alternates: {+ ...canonicalAlternates('/storage'),+ ...mdAlternates('storage'),+ },}export default function StoragePage() {diff --git a/apps/www/app/blog/[slug]/page.tsx b/apps/www/app/blog/[slug]/page.tsxindex b9d6177ca1f..1f5123d77d0 100644--- a/apps/www/app/blog/[slug]/page.tsx+++ b/apps/www/app/blog/[slug]/page.tsx@@ -10,11 +10,12 @@ import {toAbsoluteBlogImageUrl,} from '@/lib/blog-images'import { breadcrumbs } from '@/lib/breadcrumbs'+import { canonicalAlternates } from '@/lib/canonical'import { SITE_ORIGIN } from '@/lib/constants'import { parseFrontmatter } from '@/lib/frontmatter.mjs'import { blogPostingSchema, breadcrumbListSchema, serializeJsonLd } from '@/lib/json-ld'import { mdAlternates } from '@/lib/md-alternates'-import { getAllPostSlugs, getPostdata, getSortedPosts } from '@/lib/posts'+import { getAllPostSlugs, getPostdata, getSortedPosts, resolveBlogSlug } from '@/lib/posts'import type { Blog, BlogData, PostReturnType } from '@/types/post'function resolveBlogAuthors(authorField: string | undefined) {@@ -67,15 +68,20 @@ export async function generateMetadata({ params }: { params: Promise<Params> }):const parsedContent = parseFrontmatter(postContent) as unknown as MatterReturnconst blogPost = parsedContent.dataconst metaImageUrl = getAbsoluteBlogSocialImage(blogPost, SITE_ORIGIN)+ // Aliases (e.g. `/blog/postgres-13`) render the same post, so the canonical is the resolved slug.+ const canonicalSlug = resolveBlogSlug(slug) ?? slugreturn {title: blogPost.title,description: blogPost.description,- alternates: mdAlternates(`blog/${slug}`),+ alternates: {+ ...canonicalAlternates(`/blog/${encodeURIComponent(canonicalSlug)}`),+ ...mdAlternates(`blog/${slug}`),+ },openGraph: {title: blogPost.title,description: blogPost.description,- url: `${SITE_ORIGIN}/blog/${slug}`,+ url: `${SITE_ORIGIN}/blog/${canonicalSlug}`,type: 'article',images: metaImageUrl ? [metaImageUrl] : undefined,},@@ -154,12 +160,14 @@ export default async function BlogPostPage({ params }: { params: Promise<Params>}const frontmatter = parsedContent.data+ // Same identity as the canonical, so alias pages publish one post URL.+ const canonicalSlug = resolveBlogSlug(slug) ?? slugconst blogAuthors = resolveBlogAuthors(frontmatter.author)const imageUrl =getAbsoluteBlogSocialImage(frontmatter, SITE_ORIGIN) ??toAbsoluteBlogImageUrl(BLOG_PLACEHOLDER_IMAGE, SITE_ORIGIN)const blogJsonLd = blogPostingSchema({- url: `${SITE_ORIGIN}/blog/${slug}`,+ url: `${SITE_ORIGIN}/blog/${canonicalSlug}`,headline: frontmatter.title,description: frontmatter.description,image: imageUrl,@@ -169,7 +177,7 @@ export default async function BlogPostPage({ params }: { params: Promise<Params>})const breadcrumbJsonLd = breadcrumbListSchema([...breadcrumbs.blogIndex,- { name: frontmatter.title, url: `https://supabase.com/blog/${slug}` },+ { name: frontmatter.title, url: `https://supabase.com/blog/${canonicalSlug}` },])return (diff --git a/apps/www/app/blog/authors/[author]/page.tsx b/apps/www/app/blog/authors/[author]/page.tsxindex 33141c0ea20..96e022bb0be 100644--- a/apps/www/app/blog/authors/[author]/page.tsx+++ b/apps/www/app/blog/authors/[author]/page.tsx@@ -5,6 +5,7 @@ import { notFound } from 'next/navigation'import AuthorClient from './AuthorClient'import blogAuthors from '@/lib/authors.json'+import { canonicalAlternates } from '@/lib/canonical'import { getSortedPosts } from '@/lib/posts'import type PostTypes from '@/types/post'@@ -35,6 +36,9 @@ export async function generateMetadata({return {title: author ? `Blog | ${author.author}` : 'Blog | Author',description: author ? `Blog posts by ${author.author}.` : 'Latest news from the Supabase team.',+ alternates: author+ ? canonicalAlternates(`/blog/authors/${encodeURIComponent(author.author_id)}`)+ : undefined,}}diff --git a/apps/www/app/blog/categories/[category]/page.tsx b/apps/www/app/blog/categories/[category]/page.tsxindex 40fb5f34db2..ff27df63fed 100644--- a/apps/www/app/blog/categories/[category]/page.tsx+++ b/apps/www/app/blog/categories/[category]/page.tsx@@ -4,23 +4,34 @@ import { cookies } from 'next/headers'import { notFound } from 'next/navigation'import CategoryClient from './CategoryClient'-import { startCase } from '@/lib/helpers'+import { canonicalAlternates } from '@/lib/canonical'+import { decodeRouteParam, startCase } from '@/lib/helpers'import { getAllCategories, getSortedPosts } from '@/lib/posts'import type PostTypes from '@/types/post'type Params = { category: string }+// Category list is fixed per deploy, so read it once per process instead of per request.+let knownCategories: string[] | undefined+const getKnownCategories = (): string[] => (knownCategories ??= getAllCategories('_blog'))+export async function generateMetadata({params: paramsPromise,}: {params: Promise<Params>}): Promise<Metadata> {const params = await paramsPromise+ const category = decodeRouteParam(params.category)- const categoryLabel = startCase(params?.category.replaceAll('-', ' '))+ const categoryLabel = startCase(category.replaceAll('-', ' '))+ // The page calls notFound() for unknown categories, so no canonical for them.+ const isKnownCategory = getKnownCategories().includes(category)return {title: `Blog | ${categoryLabel}`,description: `Blog posts in ${categoryLabel}.`,+ alternates: isKnownCategory+ ? canonicalAlternates(`/blog/categories/${encodeURIComponent(category)}`)+ : undefined,}}@@ -30,8 +41,9 @@ export default async function CategoriesPage({params: Promise<Params>}) {const params = await paramsPromise+ const category = decodeRouteParam(params.category)- if (!getAllCategories('_blog').includes(params.category)) {+ if (!getKnownCategories().includes(category)) {notFound()}@@ -44,11 +56,11 @@ export default async function CategoriesPage({const staticPosts = getSortedPosts({directory: '_blog',limit: 0,- categories: [params.category],+ categories: [category],})const blogs = [...staticPosts] as PostTypes[]// Key by category so state (search term, view) resets when switching between// category pages rather than persisting across the reused page component.- return <CategoryClient key={params.category} posts={blogs} initialView={initialView} />+ return <CategoryClient key={category} posts={blogs} initialView={initialView} />}diff --git a/apps/www/app/blog/page.tsx b/apps/www/app/blog/page.tsxindex b2db57ca62c..17335c186a5 100644--- a/apps/www/app/blog/page.tsx+++ b/apps/www/app/blog/page.tsx@@ -5,10 +5,12 @@ import { BLOG_VIEW_COOKIE, isBlogView, type BlogView } from './blog-view'import BlogClient from './BlogClient'import SectionContainer from '@/components/Layouts/SectionContainer'import { breadcrumbs } from '@/lib/breadcrumbs'+import { canonicalAlternates } from '@/lib/canonical'import { breadcrumbListSchema, serializeJsonLd } from '@/lib/json-ld'import { getSortedPosts } from '@/lib/posts'export const metadata: Metadata = {+ alternates: canonicalAlternates('/blog'),title: 'Supabase Blog: the Postgres development platform',description: 'Get all your Supabase News on the Supabase blog.',openGraph: {diff --git a/apps/www/app/blog/tags/[tag]/page.tsx b/apps/www/app/blog/tags/[tag]/page.tsxindex 6bd13450ea2..ef61892f531 100644--- a/apps/www/app/blog/tags/[tag]/page.tsx+++ b/apps/www/app/blog/tags/[tag]/page.tsx@@ -3,19 +3,23 @@ import type { Metadata } from 'next'import { cookies } from 'next/headers'import TagClient from './TagClient'-import { startCase } from '@/lib/helpers'+import { canonicalAlternates } from '@/lib/canonical'+import { decodeRouteParam, startCase } from '@/lib/helpers'import { getAllTags, getSortedPosts } from '@/lib/posts'import type PostTypes from '@/types/post'type Params = { tag: string }+// Tag list is fixed per deploy, so read it once per process instead of per request.+let knownTags: string[] | undefined+const getKnownTags = (): string[] => (knownTags ??= getAllTags('_blog'))+// Shared by the metadata title and the visible breadcrumb so the two never// disagree. Matches the casing the blog filter chips use.const toTagLabel = (tag: string) => startCase(tag.replaceAll('-', ' '))export async function generateStaticParams() {- const tags = getAllTags('_blog')- return tags.map((tag: string) => ({ tag }))+ return getKnownTags().map((tag: string) => ({ tag }))}export async function generateMetadata({@@ -24,30 +28,30 @@ export async function generateMetadata({params: Promise<Params>}): Promise<Metadata> {const params = await paramsPromise+ const tag = decodeRouteParam(params.tag)- const tagLabel = toTagLabel(params.tag)+ const tagLabel = toTagLabel(tag)+ // Unknown tags still render (200), so skip the canonical rather than point it at a thin page.+ const isKnownTag = getKnownTags().includes(tag)return {title: `Blog | ${tagLabel}`,description: `Blog posts tagged ${tagLabel}.`,+ alternates: isKnownTag+ ? canonicalAlternates(`/blog/tags/${encodeURIComponent(tag)}`)+ : undefined,}}export default async function TagPage({ params: paramsPromise }: { params: Promise<Params> }) {const params = await paramsPromise+ const tag = decodeRouteParam(params.tag)const cookieStore = await cookies()const cookieView = cookieStore.get(BLOG_VIEW_COOKIE)?.valueconst initialView: BlogView = isBlogView(cookieView) ? cookieView : 'list'- const staticPosts = getSortedPosts({ directory: '_blog', limit: 0, tags: [params.tag] })+ const staticPosts = getSortedPosts({ directory: '_blog', limit: 0, tags: [tag] })const blogs = [...staticPosts] as PostTypes[]- return (- <TagClient- key={params.tag}- posts={blogs}- initialView={initialView}- tag={toTagLabel(params.tag)}- />- )+ return <TagClient key={tag} posts={blogs} initialView={initialView} tag={toTagLabel(tag)} />}diff --git a/apps/www/app/contribute/about/page.tsx b/apps/www/app/contribute/about/page.tsxindex e81d1587b7b..d861c4602ef 100644--- a/apps/www/app/contribute/about/page.tsx+++ b/apps/www/app/contribute/about/page.tsx@@ -1,3 +1,7 @@+import { GithubAvatar } from '~/components/Contribute/GithubAvatar'+import DefaultLayout from '~/components/Layouts/Default'+import SectionContainer from '~/components/Layouts/SectionContainer'+import { Feature, FeaturesSection as FeaturesSectionType } from '~/data/solutions/solutions.utils'import { Realtime } from 'icons'import {ArrowLeft,@@ -14,13 +18,12 @@ import {TrendingUp,Zap,} from 'lucide-react'+import type { Metadata } from 'next'import Image from 'next/image'import Link from 'next/link'-import { Badge, Button, Separator, cn } from 'ui'-import { GithubAvatar } from '~/components/Contribute/GithubAvatar'-import DefaultLayout from '~/components/Layouts/Default'-import SectionContainer from '~/components/Layouts/SectionContainer'-import { Feature, FeaturesSection as FeaturesSectionType } from '~/data/solutions/solutions.utils'+import { Badge, Button, cn, Separator } from 'ui'++import { canonicalAlternates } from '@/lib/canonical'const githubUsers = ['aantti',@@ -140,6 +143,10 @@ const especially = [},]+export const metadata: Metadata = {+ alternates: canonicalAlternates('/contribute/about'),+}+// eslint-disable-next-line no-restricted-exportsexport default function AboutPage() {return (diff --git a/apps/www/app/events/page.tsx b/apps/www/app/events/page.tsxindex 974b803471c..ca8daa56da0 100644--- a/apps/www/app/events/page.tsx+++ b/apps/www/app/events/page.tsx@@ -4,7 +4,10 @@ import { getMdxEvents, getNotionEvents, getOnDemandMdxEvents } from '~/lib/eventimport { breadcrumbListSchema, serializeJsonLd } from '~/lib/json-ld'import type { Metadata } from 'next'+import { canonicalAlternates } from '@/lib/canonical'+export const metadata: Metadata = {+ alternates: canonicalAlternates('/events'),title: 'View all Supabase events and meetups.',description:'Find all the upcoming events, webinars and meetups hosted by supabase and its community.',diff --git a/apps/www/app/partners/catalog/[slug]/page.tsx b/apps/www/app/partners/catalog/[slug]/page.tsxindex 8ee0f44ea71..0e391093708 100644--- a/apps/www/app/partners/catalog/[slug]/page.tsx+++ b/apps/www/app/partners/catalog/[slug]/page.tsx@@ -11,6 +11,7 @@ import { cache } from 'react'import remarkGfm from 'remark-gfm'import PartnerCatalogDetail from './PartnerCatalogDetail'+import { canonicalAlternates } from '@/lib/canonical'export const revalidate = 1800@@ -58,6 +59,7 @@ export async function generateMetadata({ params }: { params: Promise<Params> }):return {title: `${partner.title} | Works With Supabase`,description: partner.description,+ alternates: canonicalAlternates(`/partners/catalog/${encodeURIComponent(partner.slug)}`),openGraph: {title: `${partner.title} | Works With Supabase`,description: partner.description,diff --git a/apps/www/app/partners/catalog/page.tsx b/apps/www/app/partners/catalog/page.tsxindex 9463efce5af..8fa1814f1f4 100644--- a/apps/www/app/partners/catalog/page.tsx+++ b/apps/www/app/partners/catalog/page.tsx@@ -4,6 +4,7 @@ import { unstable_cache } from 'next/cache'import { connection } from 'next/server'import IntegrationsContent from './IntegrationsContent'+import { canonicalAlternates } from '@/lib/canonical'export const revalidate = 1800@@ -14,6 +15,7 @@ const META_DESCRIPTION ='Browse companies that build on Supabase, integrate with Supabase, or both.'export const metadata: Metadata = {+ alternates: canonicalAlternates('/partners/catalog'),title: META_TITLE,description: META_DESCRIPTION,openGraph: {diff --git a/apps/www/app/partners/page.tsx b/apps/www/app/partners/page.tsxindex 949afbf1209..11235c59ab3 100644--- a/apps/www/app/partners/page.tsx+++ b/apps/www/app/partners/page.tsx@@ -2,6 +2,7 @@ import type { Metadata } from 'next'import PartnersContent from './PartnersContent'import pageData from '@/data/partners'+import { canonicalAlternates } from '@/lib/canonical'import { listCatalogPartners } from '@/lib/marketplaceDb'export const revalidate = 1800@@ -11,6 +12,7 @@ const FEATURED_PARTNER_LIMIT = 30type FeaturedPartner = { slug: string; title: string; logo: string }export const metadata: Metadata = {+ alternates: canonicalAlternates('/partners'),title: pageData.metaTitle,description: pageData.metaDescription,openGraph: {diff --git a/apps/www/app/pricing/page.tsx b/apps/www/app/pricing/page.tsxindex e220ed5cb80..8108e61c7ea 100644--- a/apps/www/app/pricing/page.tsx+++ b/apps/www/app/pricing/page.tsx@@ -2,6 +2,7 @@ import type { Metadata } from 'next'import PricingContent from './PricingContent'import { breadcrumbs } from '@/lib/breadcrumbs'+import { canonicalAlternates } from '@/lib/canonical'import { breadcrumbListSchema, serializeJsonLd } from '@/lib/json-ld'import { mdAlternates } from '@/lib/md-alternates'@@ -9,7 +10,10 @@ export const metadata: Metadata = {title: 'Pricing & Fees | Supabase',description:"Explore Supabase fees and pricing information. Find our competitive pricing Plans, with no hidden pricing. We have a generous Free Plan for those getting started, and Pay As You Go for those scaling up. Projects on paid plans aren't paused for inactivity.",- alternates: mdAlternates('pricing'),+ alternates: {+ ...canonicalAlternates('/pricing'),+ ...mdAlternates('pricing'),+ },openGraph: {title: 'Pricing & Fees | Supabase',description:diff --git a/apps/www/app/wrapped/page.tsx b/apps/www/app/wrapped/page.tsxindex fd7d0b4bd0a..86fd454fd16 100644--- a/apps/www/app/wrapped/page.tsx+++ b/apps/www/app/wrapped/page.tsx@@ -1,7 +1,10 @@import { Metadata } from 'next'+import WrappedClient from './WrappedClient'+import { canonicalAlternates } from '@/lib/canonical'export const metadata: Metadata = {+ alternates: canonicalAlternates('/wrapped'),title: 'Supabase Wrapped 2025',description:'In 2025, developers around the world shipped faster, scaled further, and built things we never imagined. Here is what you accomplished on Supabase.',diff --git a/apps/www/canonical.test.ts b/apps/www/canonical.test.tsnew file mode 100644index 00000000000..1f7d330e662--- /dev/null+++ b/apps/www/canonical.test.ts@@ -0,0 +1,49 @@+import { describe, expect, it } from 'vitest'++import { CANONICAL_ORIGIN, canonicalAlternates, getPagesCanonicalHref } from './lib/canonical'++describe('canonicalAlternates', () => {+ it('points the canonical at production for a path', () => {+ expect(canonicalAlternates('/blog')).toEqual({ canonical: 'https://supabase.com/blog' })+ })++ it('keeps nested and dynamic paths intact', () => {+ expect(canonicalAlternates('/blog/tags/postgres')).toEqual({+ canonical: `${CANONICAL_ORIGIN}/blog/tags/postgres`,+ })+ })+})++describe('getPagesCanonicalHref', () => {+ it('uses the changelog index path', () => {+ expect(getPagesCanonicalHref('/changelog')).toBe('https://supabase.com/changelog')+ })++ it('uses a resolved changelog entry path', () => {+ expect(getPagesCanonicalHref('/changelog/17061-moving-to-org-based-billing')).toBe(+ 'https://supabase.com/changelog/17061-moving-to-org-based-billing'+ )+ })++ it('strips query strings and hashes from changelog URLs', () => {+ expect(getPagesCanonicalHref('/changelog?tag=auth#latest')).toBe(+ 'https://supabase.com/changelog'+ )+ expect(getPagesCanonicalHref('/changelog/some-entry?ref=twitter')).toBe(+ 'https://supabase.com/changelog/some-entry'+ )+ })++ it('strips a trailing slash', () => {+ expect(getPagesCanonicalHref('/changelog/')).toBe('https://supabase.com/changelog')+ })++ it('returns the origin root for the home path', () => {+ expect(getPagesCanonicalHref('/')).toBe('https://supabase.com')+ })++ it('omits the canonical while a dynamic segment is unresolved', () => {+ expect(getPagesCanonicalHref('/changelog/[slug]')).toBeUndefined()+ expect(getPagesCanonicalHref('/features/[slug]')).toBeUndefined()+ })+})diff --git a/apps/www/lib/canonical.ts b/apps/www/lib/canonical.tsnew file mode 100644index 00000000000..a9b8e5b1fc4--- /dev/null+++ b/apps/www/lib/canonical.ts@@ -0,0 +1,32 @@+import type { Metadata } from 'next'++// Canonicals always point at production, even on preview deployments, so a+// preview URL is never indexed in place of the live page.+export const CANONICAL_ORIGIN = 'https://supabase.com'++/** Canonical alternates for an app-router page. `path` must start with `/`. */+export function canonicalAlternates(path: string): Metadata['alternates'] {+ return {+ canonical: `${CANONICAL_ORIGIN}${path}`,+ }+}++/**+ * Normalizes a pages-router `asPath`: drops the query, the hash, and every+ * trailing slash. The root becomes '' so callers can pick their own fallback.+ */+export function normalizePagesPath(asPath: string): string {+ return asPath.split('?')[0].split('#')[0].replace(/\/+$/, '')+}++/**+ * Canonical href for a pages-router route, from `router.asPath`. Returns+ * undefined for unresolved dynamic routes (e.g. `/changelog/[slug]` before+ * params are known) so a literal `[slug]` is never emitted.+ */+export function getPagesCanonicalHref(asPath: string): string | undefined {+ // Root becomes '' so the canonical is the bare origin, matching the home page.+ const cleanPath = normalizePagesPath(asPath)+ if (cleanPath.includes('[')) return undefined+ return `${CANONICAL_ORIGIN}${cleanPath}`+}diff --git a/apps/www/lib/helpers.test.ts b/apps/www/lib/helpers.test.tsnew file mode 100644index 00000000000..bd8ccb0f952--- /dev/null+++ b/apps/www/lib/helpers.test.ts@@ -0,0 +1,17 @@+import { describe, expect, it } from 'vitest'++import { decodeRouteParam } from './helpers'++describe('decodeRouteParam', () => {+ it('decodes percent-encoded spaces', () => {+ expect(decodeRouteParam('event%20triggers')).toBe('event triggers')+ })++ it('leaves plain values unchanged', () => {+ expect(decodeRouteParam('postgres')).toBe('postgres')+ })++ it('returns the raw value for malformed encoding instead of throwing', () => {+ expect(decodeRouteParam('%E0%A4%A')).toBe('%E0%A4%A')+ })+})diff --git a/apps/www/lib/helpers.tsx b/apps/www/lib/helpers.tsxindex 804a065a6f7..96b4ea98b40 100644--- a/apps/www/lib/helpers.tsx+++ b/apps/www/lib/helpers.tsx@@ -235,3 +235,16 @@ export const debounce = <T extends (...args: any[]) => any>(return debounced}++/**+ * Decodes a dynamic route param. Next.js passes params percent-encoded (e.g.+ * `event%20triggers`), so decode before matching against content. A malformed+ * sequence returns the raw value rather than throwing.+ */+export function decodeRouteParam(value: string): string {+ try {+ return decodeURIComponent(value)+ } catch {+ return value+ }+}diff --git a/apps/www/lib/posts.test.ts b/apps/www/lib/posts.test.tsnew file mode 100644index 00000000000..e1e3551ab19--- /dev/null+++ b/apps/www/lib/posts.test.ts@@ -0,0 +1,21 @@+import { describe, expect, it } from 'vitest'++import { resolveBlogSlug } from './posts'++describe('resolveBlogSlug', () => {+ it('resolves an alias to the real post slug', () => {+ expect(resolveBlogSlug('postgres-13')).toBe('supabase-postgres-13')+ })++ it('resolves the date-prefixed filename to the same slug', () => {+ expect(resolveBlogSlug('2021-07-26-supabase-postgres-13')).toBe('supabase-postgres-13')+ })++ it('returns the real slug unchanged', () => {+ expect(resolveBlogSlug('supabase-postgres-13')).toBe('supabase-postgres-13')+ })++ it('returns undefined for a slug with no matching post', () => {+ expect(resolveBlogSlug('this-post-does-not-exist-xyz')).toBeUndefined()+ })+})diff --git a/apps/www/lib/posts.tsx b/apps/www/lib/posts.tsxindex da6b466aad1..31c85225b83 100644--- a/apps/www/lib/posts.tsx+++ b/apps/www/lib/posts.tsx@@ -151,18 +151,30 @@ export const getAllPostSlugs = (directory: Directories) => {return files}-export const getPostdata = async (slug: string, directory: string) => {- /**- * All files are mdx files- */- const fileType = 'mdx'- slug = slug + '.' + fileType+/**+ * Finds the file in `directory` that a URL slug resolves to. Matching is by+ * substring, so `blog-post` also finds `2022-01-01-blog-post.mdx`.+ */+export const findPostFilename = (slug: string, directory: string): string | undefined => {+ const postDirectory = path.join(process.cwd(), directory)+ const folderfiles = fs.readdirSync(postDirectory)+ return folderfiles.filter((x) => x.includes(`${slug}.mdx`))[0]+}++/**+ * Canonical slug for a blog URL: the slug of the post the URL actually resolves+ * to, so aliases like `/blog/postgres-13` map to `supabase-postgres-13`.+ */+export const resolveBlogSlug = (slug: string): string | undefined => {+ const found = findPostFilename(slug, '_blog')+ return found ? found.replace('.mdx', '').substring(FILENAME_SUBSTRING) : undefined+}+export const getPostdata = async (slug: string, directory: string) => {/*** Return full directory*/const postDirectory = path.join(process.cwd(), directory)- const folderfiles = fs.readdirSync(postDirectory)/*** Check if the file exists in the directory@@ -171,10 +183,10 @@ export const getPostdata = async (slug: string, directory: string) => {* this is so slugs like 'blog-post.mdx' will work* even if the mdx file is date namednamed like '2022-01-01-blog-post.mdx'*/- const found = folderfiles.filter((x) => x.includes(slug))[0]+ const found = findPostFilename(slug, directory)if (!found) {- throw Object.assign(new Error(`Post not found: ${slug}`), { code: 'POST_NOT_FOUND' })+ throw Object.assign(new Error(`Post not found: ${slug}.mdx`), { code: 'POST_NOT_FOUND' })}const fullPath = path.join(postDirectory, found)diff --git a/apps/www/md-alternates.test.ts b/apps/www/md-alternates.test.tsindex 27791115c60..c00936680aa 100644--- a/apps/www/md-alternates.test.ts+++ b/apps/www/md-alternates.test.ts@@ -120,9 +120,13 @@ describe('markdown alternate drift', () => {return}const source = await fs.readFile(appPagePath, 'utf-8')+ // Accept the spread form too: pages that also set a canonical merge both+ // helpers into one `alternates` object (`...mdAlternates(...)`), since a+ // second `alternates` key would be a duplicate-property error.const wiring = 'alternates: mdAlternates(`' + urlPrefix + '/${slug}`)'+ const spreadWiring = '...mdAlternates(`' + urlPrefix + '/${slug}`)'expect(- source.includes(wiring),+ source.includes(wiring) || source.includes(spreadWiring),`app/${urlPrefix}/[slug]/page.tsx must contain "${wiring}" in its generateMetadata`).toBe(true)})diff --git a/apps/www/pages/_app.tsx b/apps/www/pages/_app.tsxindex b8317ee95f0..3ae0d0c7bb5 100644--- a/apps/www/pages/_app.tsx+++ b/apps/www/pages/_app.tsx@@ -30,6 +30,7 @@ import { useWwwCommandMenuTelemetry } from '../hooks/useWwwCommandMenuTelemetry'import { MD_PAGES } from '@/app/api-v2/md/content.generated'import { Toaster } from '@/app/toaster'import { WwwCommandMenu } from '@/components/CommandMenu'+import { getPagesCanonicalHref, normalizePagesPath } from '@/lib/canonical'import { API_URL, APP_NAME, DEFAULT_META_DESCRIPTION } from '@/lib/constants'export default function App({ Component, pageProps }: AppProps) {@@ -50,7 +51,7 @@ export default function App({ Component, pageProps }: AppProps) {const themeColor = DEFAULT_FAVICON_THEME_COLOR// Advertise the .md version for AI agents on pages that have one.- const cleanPath = (router.asPath ?? '/').split('?')[0].split('#')[0].replace(/\/$/, '') || '/'+ const cleanPath = normalizePagesPath(router.asPath ?? '/') || '/'const mdSlug = cleanPath === '/' ? 'index' : cleanPath.slice(1)const mdAlternateHref = MD_PAGES.has(mdSlug)? cleanPath === '/'@@ -58,6 +59,11 @@ export default function App({ Component, pageProps }: AppProps) {: `${cleanPath}.md`: null+ // Canonical for every pages-router route. Pages that set their own canonical+ // via NextSeo override this default. Unresolved dynamic routes (e.g. `/[ref]`+ // on a page without getStaticProps) are skipped rather than emitted literally.+ const canonicalHref = getPagesCanonicalHref(router.asPath ?? '/')+return (<><Head>@@ -74,6 +80,7 @@ export default function App({ Component, pageProps }: AppProps) {<DefaultSeotitle={site_title}description={DEFAULT_META_DESCRIPTION}+ canonical={canonicalHref}openGraph={{type: 'website',url: 'https://supabase.com/',diff --git a/apps/www/pages/opt-out/[ref].tsx b/apps/www/pages/opt-out/[ref].tsxindex 6643ec162c3..5c67fb94b5f 100644--- a/apps/www/pages/opt-out/[ref].tsx+++ b/apps/www/pages/opt-out/[ref].tsx@@ -117,7 +117,11 @@ export default function OptOutPage() {function OptOutLayout({ children }: { children: React.ReactNode }) {return (<>- <NextSeo title="Supabase | Opt Out" description="Opt out of receiving emails." />+ <NextSeo+ title="Supabase | Opt Out"+ description="Opt out of receiving emails."+ noindex={true}+ /><Layout className="overflow-visible mx-auto max-w-xl mt-24 flex flex-col gap-8">{children}</Layout>