MCPcopy Create free account
hub / github.com/webdriverio/webdriverio / buildLinkRewriter

Function buildLinkRewriter

scripts/docs-generation/docsUtils.ts:38–53  ·  view source on GitHub ↗
(allDocs: Record<string, PageProps>, publishedUrlPrefix: string)

Source from the content-addressed store, hash-verified

36 * links (e.g. `./configuration.md`, `./api.md#mocking`) into Docusaurus URLs.
37 */
38export 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}

Callers 2

generateTauriDocsFunction · 0.85
generateElectronDocsFunction · 0.85

Calls 2

entriesMethod · 0.65
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…