diff --git a/__tests__/unit/shared/shared.test.ts b/__tests__/unit/shared/shared.test.ts index 4758ba3df..d676aeb08 100644 --- a/__tests__/unit/shared/shared.test.ts +++ b/__tests__/unit/shared/shared.test.ts @@ -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( diff --git a/src/shared/shared.ts b/src/shared/shared.ts index 12d4676e0..6657de630 100644 --- a/src/shared/shared.ts +++ b/src/shared/shared.ts @@ -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)