fix: insert page title literally into titleTemplate (#5470)

main
Alexandre Kohler 4 days ago committed by GitHub
parent b2540b0b9b
commit 56fa6c9df1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,10 +1,13 @@
import {
createTitle,
isRelativeBase,
joinPath,
mergeHead,
pageChunkPath,
relativePathToRoot,
type HeadConfig
type HeadConfig,
type PageData,
type SiteData
} from 'shared/shared'
describe('shared/shared', () => {
@ -25,6 +28,16 @@ describe('shared/shared', () => {
})
})
describe('createTitle', () => {
test('inserts titles containing $ literally into :title templates', () => {
const site = { title: 'Site', titleTemplate: ':title - Docs' }
const page = { title: 'Using $& and $$ in Bash' }
expect(createTitle(site as SiteData, page as PageData)).toBe(
'Using $& and $$ in Bash - Docs'
)
})
})
describe('mergeHead', () => {
test('replaces meta tags with the same key in place', () => {
expect(

@ -213,7 +213,7 @@ export function createTitle(siteData: SiteData, pageData: PageData): string {
const template = pageData.titleTemplate ?? siteData.titleTemplate
if (typeof template === 'string' && template.includes(':title')) {
return template.replace(/:title/g, title)
return template.replace(/:title/g, () => title)
}
const templateString = createTitleTemplate(siteData.title, template)

Loading…
Cancel
Save