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

main
Alexandre Kohler 5 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 { import {
createTitle,
isRelativeBase, isRelativeBase,
joinPath, joinPath,
mergeHead, mergeHead,
pageChunkPath, pageChunkPath,
relativePathToRoot, relativePathToRoot,
type HeadConfig type HeadConfig,
type PageData,
type SiteData
} from 'shared/shared' } from 'shared/shared'
describe('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', () => { describe('mergeHead', () => {
test('replaces meta tags with the same key in place', () => { test('replaces meta tags with the same key in place', () => {
expect( expect(

@ -213,7 +213,7 @@ export function createTitle(siteData: SiteData, pageData: PageData): string {
const template = pageData.titleTemplate ?? siteData.titleTemplate const template = pageData.titleTemplate ?? siteData.titleTemplate
if (typeof template === 'string' && template.includes(':title')) { 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) const templateString = createTitleTemplate(siteData.title, template)

Loading…
Cancel
Save