Files
Jeremias Menichelli e0e6a01905 chore: Remove custom ids from md headings (#52230)
## Problem

Markdown for agents hold the custom IDs, which leak into search
embeddings.

<img width="701" height="231" alt="Screenshot 2026-10-23 at 15 07 17"
src="https://github.com/user-attachments/assets/1e79e282-b954-4bf5-850c-8f0074e5b094"
/>


## Solution

Update markdown generation scripts to remove them.

<img width="399" height="297" alt="Screenshot 2026-10-23 at 15 07 11"
src="https://github.com/user-attachments/assets/af5183b8-8585-450b-a624-9127e4babfe8"
/>


<!--
## Preview links

If relevant, include links to changed pages for easy review access.

Copy the preview base URL from the Vercel bot comment on this PR. Use
the following table as an example template.

| Site | Live | Preview | Search for |
| -------------- |
-------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------
| ----------------------------- |
| WWW | [/blog/your-post](https://supabase.com/blog/your-post) |
[/blog/your-post](https://zone-www-dot-com-git-branch-name-supabase.vercel.app/blog/your-post)
| unique phrase from the change |
| Docs |
[/docs/guides/your-page](https://supabase.com/docs/guides/your-page) |
[/docs/guides/your-page](https://docs-git-branch-name-supabase.vercel.app/docs/guides/your-page)
| unique phrase from the change |
| Studio | [/dashboard](https://supabase.com/dashboard) |
[/dashboard](https://studio-git-branch-name-supabase.vercel.app/dashboard)
| unique phrase from the change |
| Design system | [/design-system](https://supabase.com/design-system) |
[/design-system](https://design-system-git-branch-name-supabase.vercel.app/design-system)
| unique phrase from the change |
| UI library | [/library](https://supabase.com/library) |
[/library](https://ui-library-git-branch-name-supabase.vercel.app/library)
| unique phrase from the change |
| Knowledge base |
[/kb/guides/your-page](https://supabase.com/kb/guides/your-page) |
[/kb/guides/your-page](https://kb-git-branch-name-supabase.vercel.app/kb/guides/your-page)
| unique phrase from the change |
-->

<!-- ## Additional context

Optionally add any other context or screenshots.

-->

## Review instructions

1. Open docs preview link.
1. Go to a page that has a custom id in their headings
1. Open the corresponding markdown file by adding .md extension to the
URL
1. Markdown version of the page should have deleted custom IDs in
headings.

## 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-10-26 11:04:54 +01:00

37 lines
1.3 KiB
TypeScript

import { visit } from 'unist-util-visit'
import { BASE_PATH } from '../src/lib/constants.ts'
import type { MarkdownTree } from './generate-markdown.ts'
/**
* Drops the custom anchor from headings like `## My heading [#my-anchor]`. The
* anchor only matters to the rendered page; left in, it leaks into the exported
* markdown and from there into search embeddings.
*/
export function stripHeadingCustomIds(tree: MarkdownTree) {
visit(tree, 'heading', (node) => {
const last = node.children.at(-1)
if (last?.type !== 'text') return
const text = last.value.trimEnd()
const anchorStart = text.lastIndexOf('[#')
if (anchorStart === -1 || !text.endsWith(']')) return
last.value = text.slice(0, anchorStart).trimEnd()
})
}
/**
* Prefixes every root-relative link with the KB base path (unless it already
* has it) and the given absolute base URL — the AST equivalent of apps/docs'
* `addBaseUrlPrefix()`.
*/
export function addBaseUrlPrefix(tree: MarkdownTree, baseUrl: string) {
visit(tree, 'link', (node) => {
if (!node.url.startsWith('/') || node.url.startsWith('//')) return
const withBase =
node.url === BASE_PATH || node.url.startsWith(`${BASE_PATH}/`)
? node.url
: `${BASE_PATH}${node.url}`
node.url = `${baseUrl}${withBase}`
})
}