UNPKG

918 BJavaScriptView Raw
1'use strict';
2
3const _ = require('lodash');
4
5function 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 // append the configId only if the asset path starts with assets/css/
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 // check if there is any extra attribute
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
29module.exports = helper;