Resolve Liquid in AUTOTITLE page titles (#34382)
This commit is contained in:
@@ -31,7 +31,9 @@ export default function rewriteLocalLinks(context) {
|
||||
// There's no languageCode or version passed, so nothing to do
|
||||
if (!currentLanguage || !currentVersion) return
|
||||
|
||||
return (tree) => {
|
||||
return async (tree) => {
|
||||
const promises = []
|
||||
|
||||
visit(tree, matcher, (node) => {
|
||||
const newHref = getNewHref(node, currentLanguage, currentVersion)
|
||||
if (newHref) {
|
||||
@@ -39,19 +41,29 @@ export default function rewriteLocalLinks(context) {
|
||||
}
|
||||
for (const child of node.children) {
|
||||
if (child.value && AUTOTITLE.test(child.value)) {
|
||||
child.value = getNewTitle(node.properties.href, context)
|
||||
promises.push(getNewTitleSetter(child, node.properties.href, context))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if (promises.length) {
|
||||
await Promise.all(promises)
|
||||
}
|
||||
|
||||
return tree
|
||||
}
|
||||
}
|
||||
|
||||
function getNewTitle(href, context) {
|
||||
async function getNewTitleSetter(child, href, context) {
|
||||
child.value = await getNewTitle(href, context)
|
||||
}
|
||||
|
||||
async function getNewTitle(href, context) {
|
||||
const page = findPage(href, context.pages, context.redirects)
|
||||
if (!page) {
|
||||
throw new Error(`Unable to find Page by href '${href}'`)
|
||||
}
|
||||
return page.title
|
||||
return await page.renderProp('title', context, { textOnly: true })
|
||||
}
|
||||
|
||||
function getNewHref(node, languageCode, version) {
|
||||
|
||||
Reference in New Issue
Block a user