@@ -27,6 +27,8 @@ import {
27
27
fontNotoColorEmoji ,
28
28
fonts ,
29
29
generateFontFacesCSS ,
30
+ getCustomFontSources ,
31
+ getFontData ,
30
32
ibmPlexMono ,
31
33
} from '@/fonts' ;
32
34
import { getSpaceLanguage } from '@/intl/server' ;
@@ -54,19 +56,7 @@ export async function CustomizationRootLayout(props: {
54
56
const mixColor = getTintMixColor ( customization . styling . primaryColor , tintColor ) ;
55
57
const sidebarStyles = getSidebarStyles ( customization ) ;
56
58
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 ) ;
70
60
71
61
// TODO: also add preconnect
72
62
@@ -87,20 +77,33 @@ export async function CustomizationRootLayout(props: {
87
77
sidebarStyles . list && `sidebar-list-${ sidebarStyles . list } ` ,
88
78
'links' in customization . styling && `links-${ customization . styling . links } ` ,
89
79
fontNotoColorEmoji . variable ,
90
- fonts [ customization . styling . font ] . variable ,
80
+ ! fontData . isCustom ? fontData . fontVariable : '' , // Only use fontVariable for default fonts
91
81
ibmPlexMono . variable
92
82
) }
93
83
>
94
84
< head >
95
85
{ customization . privacyPolicy . url ? (
96
86
< link rel = "privacy-policy" href = { customization . privacyPolicy . url } />
97
87
) : 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
+
104
107
< style
105
108
nonce = {
106
109
//Since I can't get the nonce to work for inline styles, we need to allow unsafe-inline
0 commit comments