mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem Agents have no single index of the docs markdown exports, unlike the KB's `sitemap.md`. www's `/llms.txt` and `/llms-full.txt` also read docs files from disk, which forces www's build to wait on the docs build. ## Solution **docs** - Add `build:markdown-sitemap`, which writes `public/markdown/sitemap.md`. It scans `public/markdown/**/*.md` and lists each file as `[title](url.md)`. Guide URLs are `/docs/guides/<page>.md` and the rest are `/docs/markdown/<page>.md`, built with the existing `internal-links` helpers. - Add `build:markdown-full`, which writes `public/markdown/full.md`. It concatenates the same files. - Both scripts share one file-list helper (`internals/markdown-files.ts`), so they always cover the same files and exclude `sitemap.md` and `full.md`. - Both tasks depend on `build:markdown` and are wired into `build` in turbo. - Search v2 ingestion and the `docs.tar.gz` archive now ignore both files. **www** - `/llms.txt` and `/llms-full.txt` now fetch `sitemap.md` and `full.md` from `NEXT_PUBLIC_DOCS_URL`, replacing only their docs parts. Pricing, product overviews, agent resources, the KB link and the customer stories link are unchanged. If docs is unreachable, the docs section is left out instead of returning a 404. - Remove the on-disk docs reads, the `outputFileTracingIncludes` entries, and the `docs#build:guides-markdown` dependency and docs input globs from www's turbo config. These routes were the only link between www and the docs build. `turbo-build.test.ts` is updated to match. - Add a `/docs.md` → `/docs/markdown/sitemap.md` redirect, next to the existing `/kb.md` one. Routes without a markdown export are not patched, they are simply absent from the sitemap. ## Review instructions From the Docs preview link: 1. Open /docs/markdown/sitemap.md it should show a file with all links to the docs pages available in markdown 1. Open /docs/markdown/full.md it should show a file with all the content from all the pages Sadly, only after deployed... 1. www project should return the content of both files when: a. supabase.com/llms.txt is queried should return docs sitemap.md content b. supabase.com/llms-full.txt is queried should return docs full.md content 1. supabase.com/docs.md should return sitemap.md file ## Checklist Check all before review: - [x] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [x] 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)
280 lines
11 KiB
TypeScript
280 lines
11 KiB
TypeScript
import type { NextConfig } from 'next'
|
|
import { getPathMatch } from 'next/dist/shared/lib/router/utils/path-match'
|
|
import { describe, expect, it, onTestFinished, vi } from 'vitest'
|
|
|
|
vi.mock('@sentry/nextjs', () => ({
|
|
withSentryConfig: (configFn: any) => (typeof configFn === 'function' ? configFn() : configFn),
|
|
}))
|
|
|
|
describe('next.config.mjs', () => {
|
|
it('expect the headers to always have X-Robots-Tag', async () => {
|
|
const { default: config } = (await import('./next.config.mjs')) as { default: NextConfig }
|
|
const headers = (await config.headers?.()) || []
|
|
|
|
expect(headers).toEqual(
|
|
expect.arrayContaining([
|
|
expect.objectContaining({
|
|
source: '/(docs|blog|kb|library)/:path*',
|
|
headers: [{ key: 'X-Robots-Tag', value: 'all' }],
|
|
}),
|
|
expect.objectContaining({
|
|
source: '/dashboard/:path((?!sign-in$|sign-up$).*)',
|
|
headers: [{ key: 'X-Robots-Tag', value: 'noindex' }],
|
|
}),
|
|
])
|
|
)
|
|
})
|
|
|
|
it('keeps sign-in and sign-up indexable while other dashboard paths stay noindex', async () => {
|
|
const { default: config } = (await import('./next.config.mjs')) as { default: NextConfig }
|
|
const headers = (await config.headers?.()) || []
|
|
const noindexRule = headers.find((header) => header.source.startsWith('/dashboard/'))
|
|
const matches = getPathMatch(noindexRule!.source)
|
|
|
|
expect(matches('/dashboard/sign-in')).toBe(false)
|
|
expect(matches('/dashboard/sign-up')).toBe(false)
|
|
expect(matches('/dashboard/org')).toBeTruthy()
|
|
expect(matches('/dashboard/project/abc')).toBeTruthy()
|
|
})
|
|
|
|
it('serves the published CLI schemas with CORS and a short cache', async () => {
|
|
const { default: config } = (await import('./next.config.mjs')) as { default: NextConfig }
|
|
const headers = (await config.headers?.()) || []
|
|
|
|
const schemasHeaders = headers.find((header) => header.source === '/schemas/:path*')
|
|
|
|
expect(schemasHeaders?.headers).toEqual(
|
|
expect.arrayContaining([
|
|
{ key: 'access-control-allow-origin', value: '*' },
|
|
{ key: 'cache-control', value: 'public, max-age=3600' },
|
|
])
|
|
)
|
|
expect(getPathMatch(schemasHeaders!.source)('/schemas/config/v1.json')).toBeTruthy()
|
|
})
|
|
|
|
it('routes the library and permanently redirects the legacy UI URLs', async () => {
|
|
const { default: config } = (await import('./next.config.mjs')) as { default: NextConfig }
|
|
const rewrites = await config.rewrites?.()
|
|
const afterFiles = (rewrites && 'afterFiles' in rewrites && rewrites.afterFiles) || []
|
|
const redirects = (await config.redirects?.()) || []
|
|
|
|
expect(afterFiles).toEqual(
|
|
expect.arrayContaining([
|
|
expect.objectContaining({ source: '/library' }),
|
|
expect.objectContaining({ source: '/library/:path*' }),
|
|
])
|
|
)
|
|
expect(redirects).toEqual(
|
|
expect.arrayContaining([
|
|
expect.objectContaining({
|
|
source: '/images/customers/logos/light/:path*',
|
|
destination: '/images/customers/logos/on-dark/:path*',
|
|
permanent: true,
|
|
}),
|
|
expect.objectContaining({
|
|
source: '/images/customers/logos/:slug((?!dreambase-mark\\.png)[^/.]+).png',
|
|
destination: '/images/customers/logos/on-light/:slug.png',
|
|
permanent: true,
|
|
}),
|
|
expect.objectContaining({ source: '/ui', destination: '/library', permanent: true }),
|
|
expect.objectContaining({
|
|
source: '/ui/:path*',
|
|
destination: '/library/:path*',
|
|
permanent: true,
|
|
}),
|
|
])
|
|
)
|
|
expect(
|
|
redirects.findIndex((redirect) => redirect.source === '/ui/docs/ai-editors-rules/prompts')
|
|
).toBeLessThan(redirects.findIndex((redirect) => redirect.source === '/ui/:path*'))
|
|
})
|
|
|
|
it('proxies the InstantDB migration app with its basePath prefix intact', async () => {
|
|
const { default: config } = (await import('./next.config.mjs')) as { default: NextConfig }
|
|
const rewrites = await config.rewrites?.()
|
|
const afterFiles = (rewrites && 'afterFiles' in rewrites && rewrites.afterFiles) || []
|
|
|
|
expect(afterFiles).toEqual(
|
|
expect.arrayContaining([
|
|
expect.objectContaining({
|
|
source: '/migrate/instantdb',
|
|
destination: 'https://instantdb-to-supabase.vercel.app/migrate/instantdb',
|
|
}),
|
|
expect.objectContaining({
|
|
source: '/migrate/instantdb/:path*',
|
|
destination: 'https://instantdb-to-supabase.vercel.app/migrate/instantdb/:path*',
|
|
}),
|
|
])
|
|
)
|
|
})
|
|
|
|
it('proxies Builder Day with its basePath prefix intact', async () => {
|
|
const { default: config } = (await import('./next.config.mjs')) as { default: NextConfig }
|
|
const rewrites = await config.rewrites?.()
|
|
const afterFiles = (rewrites && 'afterFiles' in rewrites && rewrites.afterFiles) || []
|
|
|
|
expect(afterFiles).toEqual(
|
|
expect.arrayContaining([
|
|
expect.objectContaining({
|
|
source: '/builderday',
|
|
destination: 'https://builderday.vercel.app/builderday',
|
|
}),
|
|
expect.objectContaining({
|
|
source: '/builderday/:path*',
|
|
destination: 'https://builderday.vercel.app/builderday/:path*',
|
|
}),
|
|
])
|
|
)
|
|
})
|
|
|
|
it('forwards zone prefetches as the page path, so each zone adds the rsc suffix once', async () => {
|
|
// later tests must not get the production rewrites from the module cache
|
|
onTestFinished(() => {
|
|
vi.unstubAllEnvs()
|
|
vi.resetModules()
|
|
})
|
|
vi.resetModules()
|
|
const zones = [
|
|
{ zone: '/docs', env: 'NEXT_PUBLIC_DOCS_URL', url: 'https://docs.example.com/docs' },
|
|
{
|
|
zone: '/library',
|
|
env: 'NEXT_PUBLIC_LIBRARY_URL',
|
|
url: 'https://library.example.com/library',
|
|
},
|
|
{
|
|
zone: '/design-system',
|
|
env: 'NEXT_PUBLIC_DESIGN_SYSTEM_URL',
|
|
url: 'https://design-system.example.com/design-system',
|
|
},
|
|
]
|
|
vi.stubEnv('NEXT_PUBLIC_VERCEL_ENV', 'production')
|
|
for (const { env, url } of zones) vi.stubEnv(env, url)
|
|
const { default: rewrites } = (await import('./lib/rewrites.js')) as {
|
|
default: Array<{ source: string; destination: string }>
|
|
}
|
|
|
|
// the first rule rewrites every path to itself, so routing goes on to the next match
|
|
const forward = (path: string) =>
|
|
rewrites
|
|
.filter((rule) => rule.source !== '/:path*')
|
|
.map((rule) => ({
|
|
destination: rule.destination,
|
|
// next matches custom routes with these options
|
|
params: getPathMatch(rule.source, { strict: true, removeUnnamedParams: true })(path),
|
|
}))
|
|
.find((match) => match.params)
|
|
|
|
for (const { zone, url } of zones) {
|
|
expect(
|
|
forward(`${zone}/guides/auth/architecture.segments/_tree.segment.rsc`),
|
|
zone
|
|
).toMatchObject({
|
|
destination: `${url}/:path`,
|
|
params: { path: 'guides/auth/architecture' },
|
|
})
|
|
expect(forward(`${zone}.segments/_tree.segment.rsc`), zone).toMatchObject({
|
|
destination: url,
|
|
})
|
|
expect(forward(`${zone}.rsc`), zone).toMatchObject({ destination: url })
|
|
expect(forward(`${zone}/guides/auth/architecture`), zone).toMatchObject({
|
|
destination: `${url}/:path*`,
|
|
})
|
|
}
|
|
})
|
|
|
|
it('routes unmatched markdown-negotiated paths to the md-404 handler via fallback rewrites', async () => {
|
|
const { default: config } = (await import('./next.config.mjs')) as { default: NextConfig }
|
|
const rewrites = await config.rewrites?.()
|
|
const fallback = (rewrites && 'fallback' in rewrites && rewrites.fallback) || []
|
|
|
|
const mdSuffixRule = fallback.find((rule) => rule.destination === '/api-v2/md-404/:path')
|
|
const acceptRule = fallback.find((rule) => rule.destination === '/api-v2/md-404/:path*')
|
|
|
|
expect(mdSuffixRule).toBeDefined()
|
|
expect(acceptRule?.has).toEqual([
|
|
{ type: 'header', key: 'accept', value: '.*text/(markdown|\\*).*' },
|
|
])
|
|
|
|
expect(getPathMatch(mdSuffixRule!.source)('/definitely-not-a-page.md')).toBeTruthy()
|
|
expect(getPathMatch(mdSuffixRule!.source)('/nested/definitely/not-a-page.md')).toBeTruthy()
|
|
expect(getPathMatch(mdSuffixRule!.source)('/definitely-not-a-page')).toBe(false)
|
|
expect(getPathMatch(acceptRule!.source)('/definitely-not-a-page')).toBeTruthy()
|
|
|
|
const acceptHeaderRegex = new RegExp(`^${acceptRule!.has![0].value}$`)
|
|
expect(acceptHeaderRegex.test('text/markdown')).toBe(true)
|
|
expect(acceptHeaderRegex.test('text/html, text/markdown;q=0.9')).toBe(true)
|
|
expect(acceptHeaderRegex.test('text/*')).toBe(true)
|
|
expect(
|
|
acceptHeaderRegex.test('text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')
|
|
).toBe(false)
|
|
})
|
|
|
|
it('permanently redirects the legacy root markdown aliases to /index.md', async () => {
|
|
const { default: config } = (await import('./next.config.mjs')) as { default: NextConfig }
|
|
const redirects = (await config.redirects?.()) || []
|
|
|
|
for (const source of ['/.md', '/homepage.md', '/llms/homepage.txt']) {
|
|
expect(redirects).toEqual(
|
|
expect.arrayContaining([
|
|
expect.objectContaining({ source, destination: '/index.md', permanent: true }),
|
|
])
|
|
)
|
|
}
|
|
|
|
expect(getPathMatch('/.md')('/.md')).toBeTruthy()
|
|
expect(getPathMatch('/.md')('/foo.md')).toBe(false)
|
|
|
|
expect(redirects).toEqual(
|
|
expect.arrayContaining([
|
|
expect.objectContaining({ source: '/index', destination: '/', permanent: true }),
|
|
])
|
|
)
|
|
expect(getPathMatch('/index')('/index.md')).toBe(false)
|
|
})
|
|
|
|
it('permanently redirects /docs.md to the docs markdown sitemap', async () => {
|
|
const { default: config } = (await import('./next.config.mjs')) as { default: NextConfig }
|
|
const redirects = (await config.redirects?.()) || []
|
|
|
|
expect(redirects).toEqual(
|
|
expect.arrayContaining([
|
|
expect.objectContaining({
|
|
source: '/docs.md',
|
|
destination: '/docs/markdown/sitemap.md',
|
|
permanent: true,
|
|
}),
|
|
])
|
|
)
|
|
})
|
|
|
|
it('preserves the filename when redirecting legacy customer logos', async () => {
|
|
const { default: config } = (await import('./next.config.mjs')) as { default: NextConfig }
|
|
const redirects = (await config.redirects?.()) || []
|
|
|
|
const darkModeRedirect = redirects.find(
|
|
(redirect) => redirect.source === '/images/customers/logos/light/:path*'
|
|
)
|
|
const lightModeRedirect = redirects.find(
|
|
(redirect) =>
|
|
redirect.source === '/images/customers/logos/:slug((?!dreambase-mark\\.png)[^/.]+).png'
|
|
)
|
|
|
|
expect(darkModeRedirect).toBeDefined()
|
|
expect(lightModeRedirect).toBeDefined()
|
|
|
|
const matchLegacyDark = getPathMatch(darkModeRedirect!.source)
|
|
const matchLegacyLight = getPathMatch(lightModeRedirect!.source)
|
|
|
|
expect(matchLegacyDark('/images/customers/logos/light/good-tape.png')).toEqual({
|
|
path: ['good-tape.png'],
|
|
})
|
|
expect(matchLegacyLight('/images/customers/logos/good-tape.png')).toEqual({
|
|
slug: 'good-tape',
|
|
})
|
|
expect(matchLegacyLight('/images/customers/logos/dreambase-mark.png')).toBe(false)
|
|
expect(matchLegacyLight('/images/customers/logos/dreambase-marketing.png')).toEqual({
|
|
slug: 'dreambase-marketing',
|
|
})
|
|
})
|
|
})
|