1
0
mirror of synced 2025-12-22 03:16:52 -05:00

Get hovercard info from pageinfo API (#36542)

This commit is contained in:
Peter Bengtsson
2023-04-24 13:04:10 -04:00
committed by GitHub
parent e647d061af
commit f4b276d0d2
3 changed files with 54 additions and 106 deletions

View File

@@ -53,7 +53,6 @@ export default function rewriteLocalLinks(context) {
const newHref = getNewHref(node, currentLanguage, currentVersion)
if (newHref) {
node.properties.href = newHref
promises.push(dataAttributesSetter(node, context))
}
for (const child of node.children) {
if (child.value) {
@@ -98,43 +97,6 @@ export default function rewriteLocalLinks(context) {
}
}
async function dataAttributesSetter(node, context) {
const href = node.properties.href
const page = findPage(href, context.pages, context.redirects)
if (!page) {
// If this happens, it's a link that might be broken or links to
// something that might not actually be an internal link to a
// existing page such as link to archived enterprise version.
return
}
let productPage = null
for (const permalink of page.permalinks) {
const rootHref = permalink.href
.split('/')
.slice(0, permalink.pageVersion === 'free-pro-team@latest' ? 3 : 4)
.join('/')
const rootPage = context.pages[rootHref]
if (rootPage) {
productPage = rootPage
break
}
}
if (productPage) {
let productTitle = await productPage.renderProp('shortTitle', context, {
textOnly: true,
})
if (!productTitle) {
productTitle = await productPage.renderProp('title', context, {
textOnly: true,
})
}
node.properties['data-product-title'] = productTitle
}
node.properties['data-title'] = await page.renderProp('title', context, { textOnly: true })
node.properties['data-intro'] = await page.renderProp('intro', context, { textOnly: true })
}
async function getNewTitleSetter(child, href, context) {
child.value = await getNewTitle(href, context)
}