fallback on failed autotitle lookups in translations (#34847)
This commit is contained in:
@@ -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 })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user