1 | 'use strict';
|
2 |
|
3 | const _ = require('lodash');
|
4 |
|
5 | function helper(paper) {
|
6 | paper.handlebars.registerHelper('stylesheet', function (assetPath) {
|
7 | const options = arguments[arguments.length - 1];
|
8 | const configId = paper.settings['theme_config_id'];
|
9 |
|
10 | const path = configId && assetPath.match(/^\/?assets\/css\//)
|
11 | ? assetPath.replace(/\.css$/, `-${configId}.css`)
|
12 | : assetPath;
|
13 |
|
14 | const url = paper.cdnify(path);
|
15 |
|
16 | let attrs = { rel: 'stylesheet' };
|
17 |
|
18 |
|
19 | if (_.isObject(options.hash)) {
|
20 | attrs = _.merge(attrs, options.hash);
|
21 | }
|
22 |
|
23 | attrs = _.map(attrs, (value, key) => `${key}="${value}"`).join( ' ');
|
24 |
|
25 | return `<link data-stencil-stylesheet href="${url}" ${attrs}>`;
|
26 | });
|
27 | }
|
28 |
|
29 | module.exports = helper;
|