diff --git a/lib/hexo/index.js b/lib/hexo/index.js index 44f47a42be..79031a47a7 100644 --- a/lib/hexo/index.js +++ b/lib/hexo/index.js @@ -352,10 +352,18 @@ Hexo.prototype._generate = function(options){ var locals = new Locals(path, data); var layoutLength = layout.length; + var cache; + + function saveCache(result){ + cache = result; + return result; + } return self.execFilter('template_locals', locals, {context: self}) .then(function(locals){ route.set(path, function(){ + if (cache != null) return cache; + var view, name; for (var i = 0; i < layoutLength; i++){ @@ -364,7 +372,7 @@ Hexo.prototype._generate = function(options){ if (view){ log.debug('Rendering %s: %s', name, chalk.magenta(path)); - return view.render(locals); + return view.render(locals).then(saveCache); } } diff --git a/lib/plugins/console/help.js b/lib/plugins/console/help.js index 60c38e5a5c..07eab97814 100644 --- a/lib/plugins/console/help.js +++ b/lib/plugins/console/help.js @@ -71,7 +71,9 @@ function printList(title, list){ if (nameB.length > length) length = nameB.length; } - return nameA - nameB; + if (nameA < nameB) return -1; + else if (nameA > nameB) return 1; + else return 0; }).forEach(function(item){ var padding = length - item.name.length + 2; str += ' ' + chalk.bold(item.name); diff --git a/lib/plugins/console/index.js b/lib/plugins/console/index.js index d442eab66d..12dfee3b91 100644 --- a/lib/plugins/console/index.js +++ b/lib/plugins/console/index.js @@ -5,7 +5,13 @@ module.exports = function(ctx){ console.register('clean', 'Removed generated files and cache.', require('./clean')); - console.register('config', 'List the current configuration.', require('./config')); + console.register('config', 'Get or set configurations.', { + usage: '[name] [value]', + arguments: [ + {name: 'name', desc: 'Setting name. Leave it blank if you want to show all configurations.'}, + {name: 'value', desc: 'New value of a setting. Leave it blank if you just want to show a single configuration.'} + ] + }, require('./config')); console.register('deploy', 'Deploy your website.', { options: [ diff --git a/test/scripts/hexo/hexo.js b/test/scripts/hexo/hexo.js index 83e85d1759..906c15d33f 100644 --- a/test/scripts/hexo/hexo.js +++ b/test/scripts/hexo/hexo.js @@ -439,7 +439,39 @@ describe('Hexo', function(){ it('_generate() - validate locals'); - it('_generate() - do nothing if it\'s generating'); + it('_generate() - do nothing if it\'s generating', function(){ + var spy = sinon.spy(); + hexo.extend.generator.register('test', spy); + + hexo._isGenerating = true; + hexo._generate(); + spy.called.should.be.false; + hexo._isGenerating = false; + }); + + it('_generate() - reset cache for new route', function(){ + var count = 0; + + hexo.theme.setView('test.swig', '{{ page.count }}'); + + hexo.extend.generator.register('test', function(){ + return { + path: 'test', + layout: 'test', + data: {count: count++} + }; + }); + + // First generation + return hexo._generate().then(function(){ + return checkStream(route.get('test'), '0'); + }).then(function(){ + // Second generation + return hexo._generate(); + }).then(function(){ + return checkStream(route.get('test'), '1'); + }); + }); it('execFilter()', function(){ hexo.extend.filter.register('exec_test', function(data){