@@ -5,14 +5,13 @@ class GoogleFontLoader extends React.PureComponent {
5
5
link = null ;
6
6
7
7
createLink = ( ) => {
8
- const { fonts } = this . props ;
8
+ const { fonts, subsets } = this . props ;
9
9
10
10
const families = fonts . reduce ( ( acc , font ) => {
11
11
const family = font . font . replace ( / + / g, '+' ) ;
12
12
const weights = ( font . weights || [ ] ) . join ( ',' ) ;
13
- const subsets = ( font . subsets || [ ] ) . join ( ',' ) ;
14
13
15
- acc . push ( family + ( weights && `:${ weights } ` ) + ( subsets && `&subset= ${ subsets } ` ) ) ;
14
+ acc . push ( family + ( weights && `:${ weights } ` ) ) ;
16
15
17
16
return acc ;
18
17
} , [ ] ) . join ( '|' ) ;
@@ -21,6 +20,10 @@ class GoogleFontLoader extends React.PureComponent {
21
20
link . rel = 'stylesheet' ;
22
21
link . href = `https://fonts.googleapis.com/css?family=${ families } ` ;
23
22
23
+ if ( subsets && Array . isArray ( subsets ) && subsets . length > 0 ) {
24
+ link . href += `&subset=${ subsets . join ( ',' ) } ` ;
25
+ }
26
+
24
27
return link ;
25
28
}
26
29
@@ -57,9 +60,9 @@ GoogleFontLoader.propTypes = {
57
60
PropTypes . shape ( {
58
61
font : PropTypes . string . isRequired ,
59
62
weights : PropTypes . arrayOf ( PropTypes . oneOf ( [ PropTypes . string , PropTypes . number ] ) ) ,
60
- subsets : PropTypes . arrayOf ( PropTypes . string ) ,
61
63
} ) ,
62
64
) . isRequired ,
65
+ subsets : PropTypes . arrayOf ( PropTypes . string ) ,
63
66
} ;
64
67
65
68
export default GoogleFontLoader ;
0 commit comments