(allDocs: Record<string, PageProps>, publishedUrlPrefix: string)
| 36 | * links (e.g. `./configuration.md`, `./api.md#mocking`) into Docusaurus URLs. |
| 37 | */ |
| 38 | export function buildLinkRewriter(allDocs: Record<string, PageProps>, publishedUrlPrefix: string) { |
| 39 | const filenameToId = new Map<string, string>() |
| 40 | for (const [id, { sourcePath }] of Object.entries(allDocs)) { |
| 41 | filenameToId.set(sourcePath, id) |
| 42 | } |
| 43 | return (content: string): string => content.replace( |
| 44 | /\.\/([\w-]+\.md)(#[\w-]+)?/g, |
| 45 | (match, filename: string, anchor: string | undefined) => { |
| 46 | const id = filenameToId.get(filename) |
| 47 | if (!id) { |
| 48 | return match |
| 49 | } |
| 50 | return `${publishedUrlPrefix}/${id}${anchor ?? ''}` |
| 51 | } |
| 52 | ) |
| 53 | } |
no test coverage detected
searching dependent graphs…