@@ -327,6 +327,8 @@ export class HeadBuilder<TOutput = HeadElement[]> {
327327 * Adds a title element that appears in browser tabs, search results, and bookmarks.
328328 * Supports both simple string titles and templated titles with dynamic substitution.
329329 *
330+ * When a template is provided via TitleOptions, the default is used initially and the template is applied to subsequent string titles.
331+ *
330332 * @param title - The document title as a string, or TitleOptions object with template and default
331333 * @returns The builder instance for method chaining
332334 *
@@ -338,9 +340,11 @@ export class HeadBuilder<TOutput = HeadElement[]> {
338340 *
339341 * @example
340342 * // Templated title with page-specific suffix
343+ * // Setting the template with default stores 'Home' as the title
341344 * const baseHead = new HeadBuilder()
342- * .addTitle({ template: '%s | My Site', default: 'Home' })
345+ * .addTitle({ template: '%s | My Site', default: 'Home' });
343346 *
347+ * // Subsequent string titles apply the template
344348 * const head = baseHead.addTitle('About Us').build(); // Results in title "About Us | My Site"
345349 */
346350 addTitle ( title : string | TitleOptions ) : this {
@@ -360,12 +364,10 @@ export class HeadBuilder<TOutput = HeadElement[]> {
360364
361365 /**
362366 * If title is provided as an object with template and default,
363- * we store the options and generate the title using the template with default .
367+ * we store the options and add the default title. Subsequent calls with string titles will use the template for generation .
364368 */
365369 this . titleOptions = title ;
366- this . addElement ( 'title' , {
367- children : this . titleOptions . template . replace ( '%s' , title . default ) ,
368- } ) ;
370+ this . addElement ( 'title' , { children : this . titleOptions . default } ) ;
369371 return this ;
370372 }
371373
0 commit comments