-
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathgoogleFont.js
More file actions
43 lines (33 loc) · 1.15 KB
/
googleFont.js
File metadata and controls
43 lines (33 loc) · 1.15 KB
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
'use strict';
function createUrl (font, weights, subsets) {
var params = '?family=' + encodeURIComponent(font);
if (weights) {
if (!(weights instanceof Array))
weights = [weights];
params += ':' + weights.join(',');
}
if (subsets) {
if (!(subsets instanceof Array))
subsets = [subsets];
params += '&subset=' + subsets.join(',');
}
return 'https://fonts.googleapis.com/css' + params;
}
exports.addon = function (renderer) {
if (process.env.NODE_ENV !== 'production') {
require('./__dev__/warnOnMissingDependencies')('hydrate', renderer, ['put']);
}
if (renderer.client) {
renderer.googleFont = function (font, weights, subsets) {
var el = document.createElement('link');
el.href = createUrl(font, weights, subsets);
el.rel = 'stylesheet';
el.type = 'text/css';
document.head.appendChild(el);
};
} else {
renderer.googleFont = function (font, weights, subsets) {
renderer.raw = "@import url('" + createUrl(font, weights, subsets) + "');" + renderer.raw;
};
}
};