Files
supabase/apps/www/canonical.test.ts
Kody Jackson f15391efee fix(www, changelog) - add in canonical URLs for product, blogs, partners, pricing pages (#51859)
## 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
2026-10-20 08:01:38 -05:00

50 lines
1.7 KiB
TypeScript

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()
})
})