1 | 'use strict';
|
2 |
|
3 | const _ = require('lodash');
|
4 | const getFonts = require('../lib/fonts');
|
5 |
|
6 | const fontResources = {
|
7 | 'Google': [
|
8 | 'https://fonts.googleapis.com',
|
9 | 'https://fonts.gstatic.com',
|
10 | ],
|
11 | };
|
12 |
|
13 | module.exports = function(paper) {
|
14 | paper.handlebars.registerHelper('resourceHints', function() {
|
15 | function format(host) {
|
16 | return `<link rel="dns-prefetch preconnect" href="${host}" crossorigin>`;
|
17 | }
|
18 |
|
19 | var hosts = [];
|
20 |
|
21 |
|
22 | const cdnUrl = paper.settings['cdn_url'] || '';
|
23 | if (cdnUrl != '') {
|
24 | hosts.push(cdnUrl);
|
25 | }
|
26 |
|
27 |
|
28 | const fontProviders = _.keys(getFonts(paper, 'providerLists'));
|
29 | _.each(fontProviders, function(provider) {
|
30 | if (typeof fontResources[provider] !== 'undefined') {
|
31 | hosts = hosts.concat(fontResources[provider]);
|
32 | }
|
33 | });
|
34 |
|
35 | return new paper.handlebars.SafeString(_.map(hosts, format).join(''));
|
36 | });
|
37 | }
|