mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
The www root markdown lived at an accidental URL: `/.md` served the
homepage markdown only because middleware strips the `.md` suffix and
the empty slug fell through to the homepage allowlist entry, while the
canonical-looking `/index.md` 404'd. The served markdown also opened
with stale legacy positioning copy that no longer matches the site. I
renamed the homepage content slug to `index` end-to-end so `/index.md`
is the one canonical markdown URL.
**Changed:**
- **`/index.md` serves the homepage markdown (200 `text/markdown`)**:
`content/md/homepage.md` renamed to `index.md`; the middleware bare-root
slug mapping, the generator's sort special-case, and the homepage
alternate tag follow, so the tag now advertises `/index.md`.
- **Legacy aliases 308 to the canonical URL**: `/.md`, `/homepage.md`,
and bare `/index` redirect via `lib/redirects.js`; `/llms/homepage.txt`
retargeted straight to `/index.md` to avoid a redirect chain. New
`next.config.test.ts` assertions pin all four.
- **Positioning refreshed**: the markdown now opens with "Supabase is
the Postgres development platform" (matching the site title), replacing
the outdated tagline.
- **Generator safety**: the redirect-exclusion filter in
`generateMdContent.mjs` now exempts the `index` slug (its HTML page is
`/`, not `/index`, so a `/index` redirect never refers to it), and the
build fails if `content/md/index.md` ever goes missing while middleware
still maps `/` to the `index` slug.
- **CI actually runs the new assertions**: I widened the `www-tests.yml`
paths filter to include `apps/www/lib/**/*.js`,
`apps/www/content/md/**`, and `apps/www/scripts/**/*.mjs`. It previously
only matched `.ts*` and the next.config files, so a PR touching only
`lib/redirects.js`, the markdown content, or the generator would skip
the tests that pin these redirects.
**Note:** the existing homepage alternate tag still exists, re-pointed
to the canonical URL. Whether the homepage should advertise a markdown
sibling at all is a separate decision; leaving it aimed at a 308 would
break tag consumers. Positioning wording is editorial, happy to tweak.
## To test
Tested on Vercel preview:
- [x] `curl -si <preview>/index.md`: expect 200 `content-type:
text/markdown`, body opens with the Postgres development platform
positioning and no longer contains the old tagline
- [x] `curl -sI <preview>/.md`: expect 308 with `location: /index.md`
- [x] `curl -sI <preview>/homepage.md` and `curl -sI
<preview>/llms/homepage.txt`: expect 308 with `location: /index.md`
- [x] `curl -sI <preview>/index`: expect 308 with `location: /`
- [x] `curl -s -H "Accept: text/markdown" -o /dev/null -w "%{http_code}
%{content_type}" <preview>/`: expect `200 text/markdown` (bare-URL
negotiation unchanged)
- [x] `curl -s <preview>/ | grep -o 'type="text/markdown"
href="[^"]*"'`: expect href ending `/index.md`
## Linear
- fixes GROWTH-1117
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- **New Features**
- Added support for `/index.md` as the canonical Markdown representation
of the homepage.
- Added permanent redirects for legacy homepage Markdown and text URLs.
- Added `/index` to `/` redirect handling.
- **Bug Fixes**
- Updated homepage metadata, alternate links, Markdown negotiation, and
content generation to consistently use the new canonical path.
- Improved homepage content description.
- **Tests**
- Expanded coverage for homepage Markdown routes, redirects, and URL
matching.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
52 lines
1.8 KiB
TypeScript
52 lines
1.8 KiB
TypeScript
import { stampFirstReferrerCookie } from 'common/first-referrer-cookie'
|
|
import { negotiateMarkdown } from 'common/markdown-negotiation'
|
|
import { NextResponse, type NextRequest } from 'next/server'
|
|
|
|
import { CHANGELOG_PAGES, MD_PAGES } from './app/api-v2/md/content.generated'
|
|
|
|
export function middleware(request: NextRequest) {
|
|
const { pathname } = request.nextUrl
|
|
|
|
const isMarkdownSuffix = pathname.endsWith('.md')
|
|
const basePathname = isMarkdownSuffix ? pathname.slice(0, -3) : pathname
|
|
|
|
// Strip trailing slash so /auth/ and /auth resolve to the same allowlist
|
|
// entry — NextURL preserves trailing-slash style on rewrite targets.
|
|
const slug = (basePathname === '/' ? 'index' : basePathname.slice(1)).replace(/\/$/, '')
|
|
const isMdEligible = MD_PAGES.has(slug)
|
|
const isChangelogEntry = CHANGELOG_PAGES.has(slug)
|
|
|
|
const decision = negotiateMarkdown(
|
|
{ acceptHeader: request.headers.get('accept') ?? '' },
|
|
{ hasMarkdownVariant: isMdEligible || isChangelogEntry, isMarkdownSuffix }
|
|
)
|
|
|
|
if (decision === 'not-acceptable') {
|
|
return new NextResponse('Not Acceptable', {
|
|
status: 406,
|
|
headers: { 'Cache-Control': 'no-store', Vary: 'Accept' },
|
|
})
|
|
}
|
|
|
|
if (decision === 'markdown') {
|
|
if (isMdEligible) {
|
|
return NextResponse.rewrite(new URL(`/api-v2/md/${slug}`, request.nextUrl))
|
|
}
|
|
// Changelog entries are static .md files in public/, not API routes.
|
|
if (isChangelogEntry) {
|
|
return NextResponse.rewrite(new URL(`/${slug}.md`, request.nextUrl))
|
|
}
|
|
}
|
|
|
|
const response = NextResponse.next()
|
|
stampFirstReferrerCookie(request, response)
|
|
return response
|
|
}
|
|
|
|
export const config = {
|
|
matcher: [
|
|
// MUST exclude _next/data to prevent full page reloads in multi-zone apps.
|
|
'/((?!api|_next/static|_next/image|_next/data|favicon.ico|__nextjs).*)',
|
|
],
|
|
}
|