Skip to content

Commit aaee6a4

Browse files
fix: add definition to node type in internal links transform (#1090)
* fix: add definition to node type in internal links transform * re-run prebuild binaries * re-run compile-prebuild after merge
1 parent 8345b64 commit aaee6a4

File tree

5 files changed

+19
-1
lines changed

5 files changed

+19
-1
lines changed

scripts/prebuild/mdx-transforms/add-version-to-internal-links/add-version-to-internal-links.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ export const rewriteInternalLinksPlugin = ({ entry, versionMetadata }) => {
7272
// Transforms the syntax tree by rewriting internal links to include the version.
7373
return flatMap(tree, (node) => {
7474
// Check if the node is a link and matches the pattern for links to rewrite
75-
if (node.type === 'link' && isLinkToRewritePattern.test(node.url)) {
75+
if (
76+
(node.type === 'link' || node.type === 'definition') &&
77+
isLinkToRewritePattern.test(node.url)
78+
) {
7679
const splitUrl = node.url.split('/')
7780
const hasVersionInPath = splitUrl.find((el) => {
7881
return (

scripts/prebuild/mdx-transforms/add-version-to-internal-links/add-version-to-internal-links.test.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,4 +361,19 @@ describe('transformRewriteInternalLinks', () => {
361361
)
362362
expect(result).toBe(expectedOutput)
363363
})
364+
365+
it('should rewrite definitions that include links', async () => {
366+
const content = `[definition]: /terraform/language/some-page`
367+
const entry = {
368+
filePath: 'content/terraform/v1.5.x/docs/language/some-file.mdx',
369+
}
370+
const expectedOutput =
371+
'[definition]: /terraform/language/v1.5.x/some-page\n'
372+
const result = await transformRewriteInternalLinks(
373+
content,
374+
entry,
375+
versionMetadata,
376+
)
377+
expect(result).toBe(expectedOutput)
378+
})
364379
})
-550 Bytes
Binary file not shown.
-412 Bytes
Binary file not shown.
-173 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)