@@ -473,23 +473,47 @@ function applyLegalBranding(html, siteConfig, language = "en") {
473473
474474function applyPublicBranding ( siteConfig ) {
475475 const slogans = siteConfig ?. branding ?. slogan ;
476- if ( ! hasConfiguredSlogan ( slogans ) ) return ;
476+ const wordmark = siteConfig ?. branding ?. wordmark ;
477+ const hasWordmark = Boolean ( wordmark ?. black || wordmark ?. green ) ;
478+ const hasSlogan = hasConfiguredSlogan ( slogans ) ;
479+ if ( ! hasWordmark && ! hasSlogan ) return ;
477480
478481 rewriteHtmlFiles ( BUILD_DIR , ( html , filePath ) => {
479- if ( ! html . includes ( 'class="instance-brand-subtitle"' ) ) return html ;
482+ let brandedHtml = html ;
483+ const brandLabel = hasWordmark ? `${ wordmark . black || "" } ${ wordmark . green || "" } ` : "" ;
484+
485+ if ( hasWordmark ) {
486+ const renderedWordmark = renderConfiguredWordmark ( siteConfig ) ;
487+ brandedHtml = brandedHtml
488+ . replace ( / < h 1 ( [ ^ > ] * ) > < s p a n > V a n i t y < \/ s p a n > < s p a n > U R L s < \/ s p a n > < \/ h 1 > / g, `<h1$1>${ renderedWordmark } </h1>` )
489+ . replace (
490+ / ( < h 1 c l a s s = " i n s t a n c e - b r a n d - t i t l e " > \s * < a h r e f = " [ ^ " ] + " a r i a - l a b e l = " ) [ ^ " ] * ( " [ ^ > ] * > ) [ \s \S ] * ?( < \/ a > \s * < \/ h 1 > ) / g,
491+ `$1${ escapeHtmlAttribute ( brandLabel ) } $2${ renderedWordmark } $3`
492+ )
493+ . replace ( / < t i t l e > ( [ ^ < ] * ?) V a n i t y U R L s ( [ ^ < ] * ?) < \/ t i t l e > / gi, `<title>$1${ escapeHtml ( brandLabel ) } $2</title>` )
494+ . replace ( / a r i a - l a b e l = " V a n i t y U R L s " / g, `aria-label="${ escapeHtmlAttribute ( brandLabel ) } "` )
495+ . replace (
496+ / ( < a c l a s s = " w o r d m a r k " h r e f = ) " h t t p s : \/ \/ v a n i t y u r l s \. l i n k \/ " / gi,
497+ `$1"https://${ escapeHtmlAttribute ( siteConfig ?. operator ?. short_domain || brandLabel ) } /"`
498+ ) ;
499+ }
500+
501+ if ( ! hasSlogan ) return brandedHtml ;
480502
481503 const language = languageForBuildHtmlFile ( filePath ) ;
482504 const slogan = renderBrandingSlogan (
483505 localizedSlogan ( slogans , language ) ,
484506 siteConfig ?. operator ,
485507 localizedSloganLinkText ( siteConfig ?. branding ?. slogan_link_text , language )
486508 ) ;
487- if ( ! slogan ) return html ;
509+ if ( ! slogan ) return brandedHtml ;
510+ const subtitle = `<p class="instance-brand-subtitle">${ slogan } </p>` ;
488511
489- return html . replace (
490- / < p c l a s s = " i n s t a n c e - b r a n d - s u b t i t l e " > [ \s \S ] * ?< \/ p > / ,
491- `<p class="instance-brand-subtitle">${ slogan } </p>`
492- ) ;
512+ if ( ! brandedHtml . includes ( 'class="instance-brand-subtitle"' ) ) {
513+ return brandedHtml . replace ( / ( < a c l a s s = " w o r d m a r k " [ \s \S ] * ?< \/ a > ) / , `$1\n\n ${ subtitle } ` ) ;
514+ }
515+
516+ return brandedHtml . replace ( / < p c l a s s = " i n s t a n c e - b r a n d - s u b t i t l e " > [ \s \S ] * ?< \/ p > / , subtitle ) ;
493517 } ) ;
494518}
495519
0 commit comments