mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem Missing canonical tags on many `www` pages (blogs, changelog entries, product pages, etc.). Part of general AEO / SEO hygiene. ## Solution Adds these in a similar pattern to `mdAlternates` (#48287) <img width="984" height="381" alt="image" src="https://github.com/user-attachments/assets/0a596f7f-b034-451f-9ea1-6804c5184388" /> ## Preview links Route type | Live | Preview -- | -- | -- Home (app router, page-level canonical) | https://supabase.com/ | https://zone-www-dot-com-git-kody-devrel-730-canonical-309a80-supabase.vercel.app/ Blog index (app router) | https://supabase.com/blog | https://zone-www-dot-com-git-kody-devrel-730-canonical-309a80-supabase.vercel.app/blog Blog post | https://supabase.com/blog/supabase-alpha-april-2020 | https://zone-www-dot-com-git-kody-devrel-730-canonical-309a80-supabase.vercel.app/blog/supabase-alpha-april-2020 Blog tag | https://supabase.com/blog/tags/postgres | https://zone-www-dot-com-git-kody-devrel-730-canonical-309a80-supabase.vercel.app/blog/tags/postgres Blog author | https://supabase.com/blog/authors/paul_copplestone | https://zone-www-dot-com-git-kody-devrel-730-canonical-309a80-supabase.vercel.app/blog/authors/paul_copplestone Product page | https://supabase.com/edge-functions | https://zone-www-dot-com-git-kody-devrel-730-canonical-309a80-supabase.vercel.app/edge-functions Pricing | https://supabase.com/pricing | https://zone-www-dot-com-git-kody-devrel-730-canonical-309a80-supabase.vercel.app/pricing Features index (pages router, _app) | https://supabase.com/features | https://zone-www-dot-com-git-kody-devrel-730-canonical-309a80-supabase.vercel.app/features Feature sub-page | https://supabase.com/features/postgres-database | https://zone-www-dot-com-git-kody-devrel-730-canonical-309a80-supabase.vercel.app/features/postgres-database Page with its own NextSeo canonical (override case) | https://supabase.com/state-of-startups-2025 | https://zone-www-dot-com-git-kody-devrel-730-canonical-309a80-supabase.vercel.app/state-of-startups-2025 Legal page, no page-level SEO (pages router default) | https://supabase.com/legal | https://zone-www-dot-com-git-kody-devrel-730-canonical-309a80-supabase.vercel.app/legal
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
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}`
|
|
}
|