Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return htmlfile => {
// Consider opts.css and map to array if it isn't one
if (opts.css) {
const css = Array.isArray(opts.css) ? opts.css : [opts.css];
return Bluebird.map(css, stylesheet => file.assertLocal(stylesheet, opts)).then(stylesheets => {
htmlfile.stylesheets = stylesheets;
return htmlfile;
});
}
// Oust extracts a list of your stylesheets
let stylesheets = flatten([
oust.raw(htmlfile.contents.toString(), 'stylesheets'),
oust.raw(htmlfile.contents.toString(), 'preload')
]).filter(link => link.$el.attr('media') !== 'print' && Boolean(link.value)).map(link => link.value);
stylesheets = uniq(stylesheets).map(file.resourcePath(htmlfile, opts));
debug('appendStylesheets', stylesheets);
if (stylesheets.length === 0) {
return Promise.reject(new Error('No usable stylesheets found in html source. Try to specify the stylesheets manually.'));
}
return Bluebird.map(stylesheets, stylesheet => file.assertLocal(stylesheet, opts)).then(stylesheets => {
htmlfile.stylesheets = stylesheets;
return htmlfile;
});
};
}
return htmlfile => {
// Consider opts.css and map to array if it isn't one
if (opts.css) {
const css = Array.isArray(opts.css) ? opts.css : [opts.css];
return Bluebird.map(css, stylesheet => file.assertLocal(stylesheet, opts)).then(stylesheets => {
htmlfile.stylesheets = stylesheets;
return htmlfile;
});
}
// Oust extracts a list of your stylesheets
let stylesheets = flatten([
oust.raw(htmlfile.contents.toString(), 'stylesheets'),
oust.raw(htmlfile.contents.toString(), 'preload')
]).filter(link => link.$el.attr('media') !== 'print' && Boolean(link.value)).map(link => link.value);
stylesheets = uniq(stylesheets).map(file.resourcePath(htmlfile, opts));
debug('appendStylesheets', stylesheets);
if (stylesheets.length === 0) {
return Promise.reject(new Error('No usable stylesheets found in html source. Try to specify the stylesheets manually.'));
}
return Bluebird.map(stylesheets, stylesheet => file.assertLocal(stylesheet, opts)).then(stylesheets => {
htmlfile.stylesheets = stylesheets;
return htmlfile;
});
};
}
function getStylesheetHrefs(file) {
if (!isVinyl(file)) {
throw new Error('Parameter file needs to be a vinyl object');
}
const stylesheets = oust.raw(file.contents.toString(), 'stylesheets');
const preloads = oust.raw(file.contents.toString(), 'preload');
return [...stylesheets, ...preloads]
.filter(link => link.$el.attr('media') !== 'print' && Boolean(link.value))
.map(link => link.value);
}
function getStylesheetHrefs(file) {
if (!isVinyl(file)) {
throw new Error('Parameter file needs to be a vinyl object');
}
const stylesheets = oust.raw(file.contents.toString(), 'stylesheets');
const preloads = oust.raw(file.contents.toString(), 'preload');
return [...stylesheets, ...preloads]
.filter(link => link.$el.attr('media') !== 'print' && Boolean(link.value))
.map(link => link.value);
}