From 2bc92e32ce78589b06d684e2a8366a9297b013a5 Mon Sep 17 00:00:00 2001 From: Nikhil Kumar Rajak Date: Tue, 15 Sep 2026 14:59:45 +0000 Subject: [PATCH] fix(section-pages): re-target type annotation links Type links on section pages kept the URL written for the module page, so `buffer.html#class-buffer` on /fs/callback-api pointed to /fs/buffer and returned a 404. Signed-off-by: Nikhil Kumar Rajak --- .changeset/section-pages-type-links.md | 5 ++++ .../section-pages/__tests__/generate.test.mjs | 30 +++++++++++++++++++ packages/react/src/section-pages/generate.mjs | 4 +++ 3 files changed, 39 insertions(+) create mode 100644 .changeset/section-pages-type-links.md diff --git a/.changeset/section-pages-type-links.md b/.changeset/section-pages-type-links.md new file mode 100644 index 00000000..71d3b4e5 --- /dev/null +++ b/.changeset/section-pages-type-links.md @@ -0,0 +1,5 @@ +--- +'@doc-kit/generator-react': patch +--- + +fix(section-pages): re-target type annotation links on chunk pages diff --git a/packages/react/src/section-pages/__tests__/generate.test.mjs b/packages/react/src/section-pages/__tests__/generate.test.mjs index 5f540922..8605ba1c 100644 --- a/packages/react/src/section-pages/__tests__/generate.test.mjs +++ b/packages/react/src/section-pages/__tests__/generate.test.mjs @@ -191,6 +191,36 @@ describe('section-pages generate', () => { assert.equal(readFile.content.children[3].children[0].url, '#class-fsdir'); }); + it('re-targets type annotation links authored for the module page', async () => { + const input = createModule(); + const readFile = input[2]; + + readFile.content.children.push({ + type: 'typeAnnotation', + value: 'string|Buffer', + data: { + links: [ + { href: 'https://example.com' }, + { href: 'buffer.html#class-buffer' }, + ], + }, + }); + + const output = await generate(input); + const chunk = output.find(e => e.path === '/fs/readFile'); + + assert.deepEqual( + chunk.content.children[2].data.links.map(({ href }) => href), + ['https://example.com', '../buffer.html#class-buffer'] + ); + + // The full page keeps its own links + assert.equal( + readFile.content.children[2].data.links[1].href, + 'buffer.html#class-buffer' + ); + }); + it('never splits excluded modules', async () => { getConfig('section-pages').exclude = ['fs']; diff --git a/packages/react/src/section-pages/generate.mjs b/packages/react/src/section-pages/generate.mjs index 8c742feb..830ef0f3 100644 --- a/packages/react/src/section-pages/generate.mjs +++ b/packages/react/src/section-pages/generate.mjs @@ -47,6 +47,10 @@ const rehome = (entry, shift, urls) => { promote(node); } else if (URL_NODE_TYPES.has(node.type) && node.url) { node.url = rewriteUrl(node.url, urls); + } else if (node.type === 'typeAnnotation') { + for (const link of node.data.links) { + link.href = rewriteUrl(link.href, urls); + } } }); };