add build date

This commit is contained in:
rozbo 2016-06-22 19:15:47 +08:00
parent 95c7f6daa0
commit 76b0dcae08
2 changed files with 20 additions and 9 deletions

View File

@ -28,12 +28,18 @@ function logic_html(str, data) {
var result = Htmlminifier(str, options);
var saved = ((str.length - result.length) / str.length * 100).toFixed(2);
log.log('neat the html: %s [ %s saved]', path, saved + '%');
var now = new Date();
// var prefix='<!-- build time:'+ now.getFullYear() +"年"+(now.getMonth() + 1)+"月"+now.getDate()+"日"
// +now.getHours()+":"+now.getMinutes()+":"
var prefix = '<!-- build time:' + now.toLocaleString() + " -->";
var end = '<!-- rebuild by neat -->';
result = prefix + result + end;
return result;
};
function logic_css(str, data) {
var hexo = this,
options = hexo.config.neat_css;
options = hexo.config.neat_css;
// Return if disabled.
if (false === options.enable) return;
@ -46,13 +52,16 @@ function logic_css(str, data) {
if (minimatch(path, exclude[i])) return str;
}
}
var log = hexo.log || console.log;
return new Promise(function (resolve, reject) {
new CleanCSS(options).minify(str, function (err, result) {
return new Promise(function(resolve, reject) {
new CleanCSS(options).minify(str, function(err, result) {
if (err) return reject(err);
var saved = ((str.length - result.styles.length) / str.length * 100).toFixed(2);
resolve(result.styles);
var prefix = '/* build time:' + new Date().toLocaleString() + "*/\n";
var end = '\n/* rebuild by neat */';
var css_result = prefix + result.styles + end;
resolve(css_result);
log.log('neat the css: %s [ %s saved]', path, saved + '%');
});
});
@ -78,8 +87,10 @@ function logic_js(str, data) {
var result = UglifyJS.minify(str, options);
var saved = ((str.length - result.code.length) / str.length * 100).toFixed(2);
log.log('neat the js: %s [ %s saved]', path, saved + '%');
return result.code;
var prefix = '// build time:' + new Date().toLocaleString() + "\n";
var end = '\n//rebuild by neat ';
var js_result = prefix + result.code + end;
return js_result;
}
@ -88,4 +99,4 @@ module.exports = {
logic_html: logic_html,
logic_css: logic_css,
logic_js: logic_js,
};
};

View File

@ -33,5 +33,5 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"version": "1.0.2"
"version": "1.0.3"
}