Files
supabase/apps/www/next.config.mjs
Jeremias Menichelli 9623f958be feat: Produce sitemap and full markdown files for docs (#54069)
## 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)
2026-12-01 09:11:29 +11:00

276 lines
8.0 KiB
JavaScript

import { remarkCodeHike } from '@code-hike/mdx'
import bundleAnalyzer from '@next/bundle-analyzer'
import nextMdx from '@next/mdx'
import { withSentryConfig } from '@sentry/nextjs'
import codeHikeTheme from 'config/code-hike.theme.json' with { type: 'json' }
import rehypeSlug from 'rehype-slug'
import remarkGfm from 'remark-gfm'
import redirects from './lib/redirects/index.js'
import remotePatterns from './lib/remotePatterns.js'
import rewrites from './lib/rewrites.js'
import securityHeaders from './lib/security-headers.js'
const withMDX = nextMdx({
extension: /\.mdx?$/,
options: {
remarkPlugins: [
[
remarkCodeHike,
{
theme: codeHikeTheme,
lineNumbers: true,
showCopyButton: true,
},
],
remarkGfm,
],
rehypePlugins: [rehypeSlug],
// This is required for `MDXProvider` component
providerImportSource: '@mdx-js/react',
},
})
const { getSecurityHeaderRules } = securityHeaders
const withBundleAnalyzer = bundleAnalyzer({
enabled: process.env.ANALYZE === 'true',
})
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
basePath: '',
pageExtensions: ['js', 'jsx', 'ts', 'tsx', 'md', 'mdx'],
trailingSlash: false,
transpilePackages: [
'ui',
'ui-patterns',
'common',
'shared-data',
'icons',
'api-types',
'marketing',
// needed to make the octokit packages work in /changelog
'@octokit/plugin-paginate-graphql',
],
experimental: {
// needed to make the octokit packages work in /changelog
esmExternals: 'loose',
},
/**
* Exclude huge directories from being traced into serverless functions
* to avoid the max size limit for Serverless Functions on Vercel:
* https://vercel.com/guides/troubleshooting-function-250mb-limit
*/
outputFileTracingExcludes: {
'*': [
// Next.js build artifacts
'.next/cache/**/*',
'.next/static/**/*',
// Next 16 creates `.next/lock` during `next build` and deletes it on exit. Routes that read
// `process.cwd()` get the whole app dir traced, so Vercel would try to deploy the missing file.
'.next/lock',
// Static assets
'public/**/*',
],
},
reactStrictMode: true,
images: {
dangerouslyAllowSVG: false,
// Next 16 rejects local images with a query string (e.g. `/images/blog/foo/thumb.png?v=3`,
// used for cache busting) unless `localPatterns` allows it. Omitting `search` allows any.
localPatterns: [{ pathname: '/**' }],
// Next 16 only allows `quality` values listed here (default is [75]); the app uses 75, 80 and 100.
qualities: [75, 80, 100],
remotePatterns,
},
async headers() {
return [
{
source: '/changelog-rss.xml',
headers: [
{ key: 'Content-Type', value: 'application/rss+xml; charset=utf-8' },
{ key: 'X-Content-Type-Options', value: 'nosniff' },
{ key: 'Cache-Control', value: 'public, s-maxage=900, stale-while-revalidate=900' },
],
},
{
source: '/changelog-rss/:slug.xml',
headers: [
{ key: 'Content-Type', value: 'application/rss+xml; charset=utf-8' },
{ key: 'X-Content-Type-Options', value: 'nosniff' },
{ key: 'Cache-Control', value: 'public, s-maxage=900, stale-while-revalidate=900' },
],
},
{
source: '/changelog/:slug.md',
headers: [
{ key: 'Content-Type', value: 'text/markdown; charset=utf-8' },
{ key: 'X-Content-Type-Options', value: 'nosniff' },
{ key: 'Cache-Control', value: 'public, s-maxage=900, stale-while-revalidate=900' },
{ key: 'Vary', value: 'Accept' },
],
},
{
source: '/changelog.md',
headers: [
{ key: 'Content-Type', value: 'text/markdown; charset=utf-8' },
{ key: 'X-Content-Type-Options', value: 'nosniff' },
{ key: 'Cache-Control', value: 'public, s-maxage=900, stale-while-revalidate=900' },
{ key: 'Vary', value: 'Accept' },
],
},
{
source: '/',
headers: [
{
key: 'Link',
value:
'</.well-known/api-catalog>; rel="api-catalog", </.well-known/ai-catalog.json>; rel="ai-catalog"',
},
],
},
{
source: '/.well-known/api-catalog',
headers: [
{ key: 'content-type', value: 'application/linkset+json' },
{ key: 'access-control-allow-origin', value: '*' },
],
},
{
source: '/.well-known/vercel/flags',
headers: [
{
key: 'content-type',
value: 'application/json',
},
],
},
{
source: '/schemas/:path*',
headers: [
{ key: 'access-control-allow-origin', value: '*' },
{ key: 'cache-control', value: 'public, max-age=3600' },
],
},
{
source: '/favicon/:slug*',
headers: [{ key: 'cache-control', value: 'public, max-age=86400' }],
},
{
source: '/(.*)',
headers: [
{
key: 'Strict-Transport-Security',
value:
process.env.NEXT_PUBLIC_IS_PLATFORM === 'true' && process.env.VERCEL === '1'
? 'max-age=31536000; includeSubDomains; preload'
: '',
},
],
},
...getSecurityHeaderRules(rewrites),
{
source: '/(docs|blog|kb|library)/:path*',
headers: [
{
key: 'X-Robots-Tag',
value: 'all',
},
],
},
{
// Public auth pages are indexable; every other dashboard path stays noindex
source: '/dashboard/:path((?!sign-in$|sign-up$).*)',
headers: [
{
key: 'X-Robots-Tag',
value: 'noindex',
},
],
},
{
source: '/enterprise-terms',
headers: [
{
key: 'X-Robots-Tag',
value: 'noindex, nofollow',
},
],
},
{
source: '/sla',
headers: [
{
key: 'X-Robots-Tag',
value: 'noindex, nofollow',
},
],
},
]
},
async rewrites() {
return {
afterFiles: rewrites,
fallback: [
{
source: '/:path(.*\\.md)',
destination: '/api-v2/md-404/:path',
},
{
source: '/:path*',
has: [{ type: 'header', key: 'accept', value: '.*text/(markdown|\\*).*' }],
destination: '/api-v2/md-404/:path*',
},
],
}
},
async redirects() {
return redirects
},
typescript: {
// On previews, typechecking is run via GitHub Action only for efficiency
// On production, we turn it on to prevent errors from conflicting PRs getting into
// prod
ignoreBuildErrors: process.env.NEXT_PUBLIC_VERCEL_ENV === 'production' ? false : true,
},
}
// next.config.js.
const configExport = () => {
const plugins = [withMDX, withBundleAnalyzer]
return plugins.reduce((acc, next) => next(acc), nextConfig)
}
export default withSentryConfig(configExport, {
// For all available options, see:
// https://www.npmjs.com/package/@sentry/webpack-plugin#options
org: 'supabase',
project: 'www',
applicationKey: 'supabase-www',
webpack: {
treeshake: {
// Automatically tree-shake Sentry logger statements to reduce bundle size
removeDebugLogging: true,
},
},
// Only print logs for uploading source maps in CI
silent: !process.env.CI,
// For all available options, see:
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
// Upload a larger set of source maps for prettier stack traces (increases build time)
widenClientFileUpload: true,
// Uncomment to route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
// This can increase your server load as well as your hosting bill.
// Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-
// side errors will fail.
// tunnelRoute: "/monitoring",
})