fix: unescape html entities in page title (#1392)
This commit is contained in:
parent
18af058e4d
commit
3c888d3914
|
@ -17,10 +17,30 @@ export function setupPageHeader() {
|
||||||
dir: () => localeMap[locale.value] ?? 'auto',
|
dir: () => localeMap[locale.value] ?? 'auto',
|
||||||
},
|
},
|
||||||
titleTemplate: (title) => {
|
titleTemplate: (title) => {
|
||||||
let titleTemplate = title ? `${title} | ` : ''
|
let titleTemplate = title ?? ''
|
||||||
titleTemplate += t('app_name')
|
|
||||||
|
if (titleTemplate.match(/&[a-z0-9#]+;/gi)) {
|
||||||
|
titleTemplate = unescapeTitleTemplate(titleTemplate, [
|
||||||
|
['"', ['"', '"']],
|
||||||
|
['&', ['&', '&']],
|
||||||
|
['\'', [''', ''']],
|
||||||
|
['\u003C', ['<', '<']],
|
||||||
|
['\u003E', ['>', '>']],
|
||||||
|
])
|
||||||
|
if (titleTemplate.length > 60)
|
||||||
|
titleTemplate = `${titleTemplate.slice(0, 60)}...${titleTemplate.endsWith('"') ? '"' : ''}`
|
||||||
|
|
||||||
|
if (!titleTemplate.includes('"'))
|
||||||
|
titleTemplate = `"${titleTemplate}"`
|
||||||
|
}
|
||||||
|
else if (titleTemplate.length > 60) {
|
||||||
|
titleTemplate = `${titleTemplate.slice(0, 60)}...${titleTemplate.endsWith('"') ? '"' : ''}`
|
||||||
|
}
|
||||||
|
|
||||||
|
titleTemplate += ` | ${t('app_name')}`
|
||||||
if (buildInfo.env !== 'release')
|
if (buildInfo.env !== 'release')
|
||||||
titleTemplate += ` (${buildInfo.env})`
|
titleTemplate += ` (${buildInfo.env})`
|
||||||
|
|
||||||
return titleTemplate
|
return titleTemplate
|
||||||
},
|
},
|
||||||
link: process.client && useRuntimeConfig().public.pwaEnabled
|
link: process.client && useRuntimeConfig().public.pwaEnabled
|
||||||
|
@ -32,3 +52,12 @@ export function setupPageHeader() {
|
||||||
: [],
|
: [],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function unescapeTitleTemplate(titleTemplate: string, replacements: [string, string[]][]) {
|
||||||
|
let result = titleTemplate
|
||||||
|
for (const [replacement, entities] of replacements) {
|
||||||
|
for (const e of entities)
|
||||||
|
result = result.replaceAll(e, replacement)
|
||||||
|
}
|
||||||
|
return result.trim()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue