Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/section-pages-type-links.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@doc-kit/generator-react': patch
---

fix(section-pages): re-target type annotation links on chunk pages
30 changes: 30 additions & 0 deletions packages/react/src/section-pages/__tests__/generate.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand Down
4 changes: 4 additions & 0 deletions packages/react/src/section-pages/generate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
});
};
Expand Down
Loading