-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathgatsby-ssr.js
51 lines (43 loc) · 1.15 KB
/
gatsby-ssr.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use strict'
var _react = require('react')
var _react2 = _interopRequireDefault(_react)
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { default: obj }
}
var format = function format(string) {
return string
.split(' ')
.map(function(s) {
return s.replace(/^\w/, function(s) {
return s.toUpperCase()
})
})
.join(' ')
}
var getFonts = function getFonts(options) {
return options.fonts
.map(format)
.join('|')
.replace(/ /g, '+')
}
function getDisplay(options) {
return options.display ? '&display=' + options.display : ''
}
exports.onRenderBody = function(_ref, options) {
var setHeadComponents = _ref.setHeadComponents
var link = 'https://fonts.googleapis.com/css?family=' + getFonts(options) + getDisplay(options)
setHeadComponents([
_react2.default.createElement('link', {
key: 'google-fonts-preconnect',
rel: 'preconnect',
href: 'https://fonts.gstatic.com/',
crossOrigin: 'anonymous'
}),
_react2.default.createElement('link', {
key: 'fonts',
href: link,
rel: 'stylesheet',
crossOrigin: 'anonymous'
})
])
}