File tree 2 files changed +32
-1
lines changed
2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -153,7 +153,7 @@ export function createUnhead<T = ResolvableHead>(resolvedOptions: CreateHeadOpti
153
153
154
154
if ( titleTemplate ) {
155
155
const titleTemplateFn = titleTemplate ?. textContent
156
- head . _titleTemplate = typeof titleTemplateFn === 'string' ? titleTemplateFn : undefined
156
+ head . _titleTemplate = titleTemplateFn
157
157
if ( titleTemplateFn ) {
158
158
// @ts -expect-error todo
159
159
let newTitle = ( typeof titleTemplateFn === 'function' ? titleTemplateFn ( title ?. textContent ) : titleTemplateFn )
Original file line number Diff line number Diff line change @@ -268,4 +268,35 @@ describe('inferSeoMetaPlugin', () => {
268
268
}
269
269
` )
270
270
} )
271
+ it ( 'infers og:title from function titleTemplate with default value' , async ( ) => {
272
+ const head = createHead ( {
273
+ disableDefaults : true ,
274
+ plugins : [ InferSeoMetaPlugin ( ) ] ,
275
+ } )
276
+
277
+ // Simulate the app.vue setup with a function titleTemplate
278
+ head . push ( {
279
+ title : null ,
280
+ titleTemplate : ( titleChunk ) => {
281
+ return titleChunk ? `${ titleChunk } - Website` : 'Welcome to Website'
282
+ } ,
283
+ meta : [
284
+ {
285
+ name : 'description' ,
286
+ content : 'Description.' ,
287
+ } ,
288
+ {
289
+ name : 'theme-color' ,
290
+ content : '#007ed4' ,
291
+ } ,
292
+ ] ,
293
+ } )
294
+
295
+ const result = await renderSSRHead ( head )
296
+
297
+ expect ( result . headTags ) . toContain ( '<title>Welcome to Website</title>' )
298
+ expect ( result . headTags ) . toContain ( '<meta property="og:title" data-infer="" content="Welcome to Website">' )
299
+ expect ( result . headTags ) . toContain ( '<meta name="description" content="Description.">' )
300
+ expect ( result . headTags ) . toContain ( '<meta name="theme-color" content="#007ed4">' )
301
+ } )
271
302
} )
You can’t perform that action at this time.
0 commit comments