@@ -27,6 +27,8 @@ import {
2727 fontNotoColorEmoji ,
2828 fonts ,
2929 generateFontFacesCSS ,
30+ getCustomFontSources ,
31+ getFontData ,
3032 ibmPlexMono ,
3133} from '@/fonts' ;
3234import { getSpaceLanguage } from '@/intl/server' ;
@@ -54,19 +56,7 @@ export async function CustomizationRootLayout(props: {
5456 const mixColor = getTintMixColor ( customization . styling . primaryColor , tintColor ) ;
5557 const sidebarStyles = getSidebarStyles ( customization ) ;
5658 const { infoColor, successColor, warningColor, dangerColor } = getSemanticColors ( customization ) ;
57-
58- const font = customization . styling . font as CustomizationFont ;
59-
60- const hasCustomFont = typeof font !== 'string' ;
61-
62- // Add custom font handling
63- const customFontCSS = hasCustomFont ? generateFontFacesCSS ( font ) : '' ;
64-
65- const customFontLinks = hasCustomFont
66- ? customization . styling . font . faces . map ( ( face ) => face . url )
67- : [ ] ;
68-
69- console . log ( 'customFontLinks' , customFontLinks , customization . styling . font ) ;
59+ const fontData = getFontData ( customization . styling . font ) ;
7060
7161 // TODO: also add preconnect
7262
@@ -87,20 +77,33 @@ export async function CustomizationRootLayout(props: {
8777 sidebarStyles . list && `sidebar-list-${ sidebarStyles . list } ` ,
8878 'links' in customization . styling && `links-${ customization . styling . links } ` ,
8979 fontNotoColorEmoji . variable ,
90- fonts [ customization . styling . font ] . variable ,
80+ ! fontData . isCustom ? fontData . fontVariable : '' , // Only use fontVariable for default fonts
9181 ibmPlexMono . variable
9282 ) }
9383 >
9484 < head >
9585 { customization . privacyPolicy . url ? (
9686 < link rel = "privacy-policy" href = { customization . privacyPolicy . url } />
9787 ) : null }
98- { hasCustomFont && customFontLinks . length > 0
99- ? customFontLinks . map ( ( link ) => (
100- < link rel = "preload" href = { link } as = "font" crossOrigin = "anonymous" />
101- ) )
102- : null }
103- { hasCustomFont ? < style > { customFontCSS } </ style > : null }
88+
89+ { /* Font preloading for custom fonts */ }
90+ { fontData . isCustom &&
91+ fontData . fontSources . map ( ( { url, format } ) => (
92+ < link
93+ key = { url . href }
94+ rel = "preload"
95+ href = { url . href }
96+ as = "font"
97+ type = { format ? `font/${ format } ` : undefined }
98+ crossOrigin = "anonymous"
99+ />
100+ ) ) }
101+
102+ { /* Custom font CSS */ }
103+ { fontData . isCustom && fontData . fontCSS && (
104+ < style id = "custom-font-styles" > { fontData . fontCSS } </ style >
105+ ) }
106+
104107 < style
105108 nonce = {
106109 //Since I can't get the nonce to work for inline styles, we need to allow unsafe-inline
0 commit comments