1
0
mirror of synced 2025-12-21 19:06:49 -05:00

fallback on failed autotitle lookups in translations (#34847)

This commit is contained in:
Peter Bengtsson
2023-02-17 13:02:44 -05:00
committed by GitHub
parent 4cd28fd735
commit 5cb5ffa5c1
2 changed files with 13 additions and 3 deletions

View File

@@ -17,6 +17,11 @@ const externalRedirects = readJsonFile('./lib/redirects/external-sites.json')
// Meaning it can be 'AUTOTITLE ' or ' AUTOTITLE' or 'AUTOTITLE'
const AUTOTITLE = /^\s*AUTOTITLE\s*$/
// This is exported because in translations, we need to treat this as
// one of those Liquid parsing errors which happens on corrupted translations
// which we use to know that we need to fall back to English.
export class TitleFromAutotitleError extends Error {}
// Matches any <a> tags with an href that starts with `/`
const matcher = (node) =>
node.type === 'element' &&
@@ -75,7 +80,7 @@ async function getNewTitleSetter(child, 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}'`)
throw new TitleFromAutotitleError(`Unable to find Page by href '${href}'`)
}
return await page.renderProp('title', context, { textOnly: true })
}