Skip to content

Commit 2bc92e3

Browse files
committed
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 <ryzrr.official@gmail.com>
1 parent 136de98 commit 2bc92e3

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@doc-kit/generator-react': patch
3+
---
4+
5+
fix(section-pages): re-target type annotation links on chunk pages

packages/react/src/section-pages/__tests__/generate.test.mjs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,36 @@ describe('section-pages generate', () => {
191191
assert.equal(readFile.content.children[3].children[0].url, '#class-fsdir');
192192
});
193193

194+
it('re-targets type annotation links authored for the module page', async () => {
195+
const input = createModule();
196+
const readFile = input[2];
197+
198+
readFile.content.children.push({
199+
type: 'typeAnnotation',
200+
value: 'string|Buffer',
201+
data: {
202+
links: [
203+
{ href: 'https://example.com' },
204+
{ href: 'buffer.html#class-buffer' },
205+
],
206+
},
207+
});
208+
209+
const output = await generate(input);
210+
const chunk = output.find(e => e.path === '/fs/readFile');
211+
212+
assert.deepEqual(
213+
chunk.content.children[2].data.links.map(({ href }) => href),
214+
['https://example.com', '../buffer.html#class-buffer']
215+
);
216+
217+
// The full page keeps its own links
218+
assert.equal(
219+
readFile.content.children[2].data.links[1].href,
220+
'buffer.html#class-buffer'
221+
);
222+
});
223+
194224
it('never splits excluded modules', async () => {
195225
getConfig('section-pages').exclude = ['fs'];
196226

packages/react/src/section-pages/generate.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ const rehome = (entry, shift, urls) => {
4747
promote(node);
4848
} else if (URL_NODE_TYPES.has(node.type) && node.url) {
4949
node.url = rewriteUrl(node.url, urls);
50+
} else if (node.type === 'typeAnnotation') {
51+
for (const link of node.data.links) {
52+
link.href = rewriteUrl(link.href, urls);
53+
}
5054
}
5155
});
5256
};

0 commit comments

Comments
 (0)