Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hexo-filter-optimize

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hexo-filter-optimize - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

lib/concator.js

123

lib/filter.js

@@ -7,2 +7,3 @@ // the main filter function

var streamRead = require('./stream');
var concator = require('./concator');

@@ -18,2 +19,3 @@ var Jsdom = jsdom.JSDOM;

var js = config.js;
var removeComments = config.remove_comments;

@@ -23,3 +25,3 @@ var list = route.list();

// only filter html files.
var routes = list.filter(function (path) {
var htmls = list.filter(function (path) {
return minimatch(path, '**/*.html', { nocase: true });

@@ -43,3 +45,2 @@ });

// grab the defined inline css files
var inlines = [];
var inlineCssText = '';

@@ -49,3 +50,3 @@ var first = Promise.resolve();

if (css.enable) {
inlines = list.filter(function (path) {
var inlines = list.filter(function (path) {
if (inExcludes(path, css.excludes)) {

@@ -58,12 +59,8 @@ return false;

if (inlines.length > 0) {
first = Promise.map(inlines, function (path) {
var stream = route.get(path);
return streamRead(stream)
.then(function (data) {
inlineCssText += data;
})
.catch(function (err) {
logger.log('Errors when get the inline css: ', path, err);
});
});
first = concator.bundleFiles(inlines, list, route, '', removeComments)
.then(function (content) {
inlineCssText = content;
}).catch(function (err) {
logger.log('Errors when get the inline css: ', err);
});
}

@@ -80,3 +77,3 @@ }

return first.then(function () {
return Promise.map(routes, function (path) {
return Promise.map(htmls, function (path) {
var stream = route.get(path);

@@ -160,8 +157,6 @@ return streamRead(stream)

// record it
if (scriptText.length > 0) {
scriptText += ';\n';
}
scriptText += el.textContent;
scriptText = concator.combine(scriptText, el.textContent,
';', removeComments);
el.remove();
} else if (src[0] === '/' && src[1] !== '/') {
} else if (src && src[0] === '/' && src[1] !== '/') {
if (bundleJsList.indexOf(src) < 0) {

@@ -248,14 +243,2 @@ bundleJsList.push(src);

// if (bundleCssList.length > 0) {
// var bundleCss = doc.createElement('link');
// bundleCss.rel = 'stylesheet';
// bundleCss.href = root + 'style.css';
// if (noscript != null) {
// doc.head.insertBefore(bundleCss, noscript);
// } else {
// doc.head.appendChild(bundleCss);
// }
// changed = true;
// }
if (changed) {

@@ -274,69 +257,25 @@ // get the replaced string

}).then(function () {
var p = Promise.resolve();
var concat = function (path, func) {
return function () {
var stream = route.get(path);
return streamRead(stream).then(func);
};
};
// bundle the styles
var contentCss = '';
var fileCss = [];
bundleCssList.filter(function (b) {
var file = list.filter(function (path) {
return b.indexOf(path) >= 0;
});
if (file.length > 0) {
fileCss.push(concat(file[0], function (str) {
// console.log('bundle: ' + path);
if (contentCss.length > 0) {
contentCss += '\n';
}
contentCss += str;
}));
}
});
for (var i = 0; i < fileCss.length; i++) {
(function (n) {
p = p.then(function () {
return fileCss[n]();
var p;
if (bundleCssList.length > 0) {
p = concator.bundleFiles(bundleCssList, list, route, '', removeComments)
.then(function (content) {
route.set(root + 'style.css', content);
});
})(i);
} else {
p = Promise.resolve();
}
p = p.then(function () {
return route.set(root + 'style.css', contentCss);
});
// bundle the js
var contentJs = '';
var fileJs = [];
bundleJsList.filter(function (b) {
var file = list.filter(function (path) {
return b.indexOf(path) >= 0;
if (bundleJsList.length > 0) {
p = p.then(function () {
concator.bundleFiles(bundleJsList, list, route, ';', removeComments)
.then(function (content) {
if (content.length > 0) {
route.set(root + 'bundle.js', content);
}
});
});
if (file.length > 0) {
fileJs.push(concat(file[0], function (str) {
// console.log('bundle: ' + path);
if (contentJs.length > 0) {
contentJs += ';\n';
}
contentJs += str;
}));
}
});
for (var i = 0; i < fileJs.length; i++) {
(function (n) {
p = p.then(function () {
return fileJs[n]();
});
})(i);
}
return p.then(function () {
return route.set(root + 'bundle.js', contentJs);
});
return p;
});
};
{
"name": "hexo-filter-optimize",
"version": "0.2.2",
"version": "0.2.3",
"description": "A hexo plugin that optimize the pages loading speed.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -32,2 +32,4 @@ # hexo-filter-optimize

remove_query_string: true
# remove the surrounding comments in each of the bundled files
remove_comments: false
css:

@@ -34,0 +36,0 @@ enable: true

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc