11async function loadGoogleFont (
22 font : string ,
3- text : string
3+ text : string ,
4+ weight : number
45) : Promise < ArrayBuffer > {
5- const API = `https://fonts.googleapis.com/css2?family=${ font } &text=${ encodeURIComponent ( text ) } ` ;
6+ const API = `https://fonts.googleapis.com/css2?family=${ font } :wght@ ${ weight } &text=${ encodeURIComponent ( text ) } ` ;
67
78 const css = await (
89 await fetch ( API , {
@@ -14,7 +15,7 @@ async function loadGoogleFont(
1415 ) . text ( ) ;
1516
1617 const resource = css . match (
17- / s r c : u r l \( ( .+ ) \) f o r m a t \( ' ( o p e n t y p e | t r u e t y p e ) ' \) /
18+ / s r c : u r l \( ( .+ ? ) \) f o r m a t \( ' ( o p e n t y p e | t r u e t y p e ) ' \) /
1819 ) ;
1920
2021 if ( ! resource ) throw new Error ( "Failed to download dynamic font" ) ;
@@ -25,8 +26,7 @@ async function loadGoogleFont(
2526 throw new Error ( "Failed to download dynamic font. Status: " + res . status ) ;
2627 }
2728
28- const fonts : ArrayBuffer = await res . arrayBuffer ( ) ;
29- return fonts ;
29+ return res . arrayBuffer ( ) ;
3030}
3131
3232async function loadGoogleFonts (
@@ -42,16 +42,16 @@ async function loadGoogleFonts(
4242 style : "normal" ,
4343 } ,
4444 {
45- name : "Source Han Serif " ,
46- font : "Noto+Serif+SC :wght@700" ,
45+ name : "IBM Plex Mono " ,
46+ font : "IBM+Plex+Mono :wght@700" ,
4747 weight : 700 ,
4848 style : "bold" ,
4949 } ,
5050 ] ;
5151
5252 const fonts = await Promise . all (
5353 fontsConfig . map ( async ( { name, font, weight, style } ) => {
54- const data = await loadGoogleFont ( font , text ) ;
54+ const data = await loadGoogleFont ( font , text , weight ) ;
5555 return { name, data, weight, style } ;
5656 } )
5757 ) ;
0 commit comments