Skip to content

Commit 9a04b16

Browse files
Saturn226heiskr
andauthored
updated popover links (#52205)
Co-authored-by: Kevin Heis <[email protected]>
1 parent fae70a0 commit 9a04b16

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/links/components/LinkPreviewPopover.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,13 @@ function fillPopover(
308308
// All a.href attributes are always full absolute URLs, as a string.
309309
// We assume that the "product landing page" is the first
310310
// portion of all links.
311-
productHeadLink.href = linkURL.pathname.split('/').slice(0, 3).join('/')
311+
const regex = /^\/(?<lang>\w{2}\/)?(?<version>[\w-]+@[\w-.]+\/)?(?<product>[\w-]+\/)?/
312+
const match = regex.exec(linkURL.pathname)
313+
if (match?.groups) {
314+
const { lang, version, product } = match.groups
315+
const productURL = [lang, version, product].map((n) => n || '').join('')
316+
productHeadLink.href = `${linkURL.origin}/${productURL}`
317+
}
312318
productHead.style.display = 'block'
313319
}
314320
} else {

0 commit comments

Comments
 (0)