mirror of
https://github.com/KevinMidboe/inline-html.git
synced 2025-10-29 17:40:29 +00:00
Fixed bug where query strings and hashes were not ignored on css url data type local paths.
This commit is contained in:
@@ -1,21 +1,43 @@
|
||||
var _ = require('lodash');
|
||||
var datauri = require('datauri');
|
||||
var isLocalPath = require('is-local-path');
|
||||
var path = require('path');
|
||||
var postcss = require('postcss');
|
||||
var url = require('postcss-url');
|
||||
var postcssUrl = require('postcss-url');
|
||||
var url = require('url');
|
||||
|
||||
/**
|
||||
* Returns url path without query string and hash if present.
|
||||
*
|
||||
* @param path
|
||||
*
|
||||
* @returns path
|
||||
*/
|
||||
var clean = function (path) {
|
||||
path = url.parse(path);
|
||||
path = _.pick(path, ['protocol', 'host', 'pathname']);
|
||||
return url.format(path);
|
||||
};
|
||||
/**
|
||||
* Convert local url data type paths to datauris.
|
||||
*
|
||||
* @param css
|
||||
* @param filename
|
||||
* @returns {{css: (css|any), files: Array}}
|
||||
*/
|
||||
var inline = function (css, filename) {
|
||||
var files = [];
|
||||
var basePath = path.dirname(filename);
|
||||
var result = postcss()
|
||||
.use(url({
|
||||
url: function (url) {
|
||||
if (isLocalPath(url)) {
|
||||
url = path.resolve(basePath, url);
|
||||
files.push(url);
|
||||
url = datauri(url);
|
||||
.use(postcssUrl({
|
||||
url: function (urlPath) {
|
||||
if (isLocalPath(urlPath)) {
|
||||
urlPath = clean(urlPath);
|
||||
urlPath = path.resolve(basePath, urlPath);
|
||||
files.push(urlPath);
|
||||
urlPath = datauri(urlPath);
|
||||
}
|
||||
return url;
|
||||
return urlPath;
|
||||
}
|
||||
}))
|
||||
.process(css);
|
||||
|
||||
Reference in New Issue
Block a user