diff --git a/lib/hexo/index.js b/lib/hexo/index.js index 97a9566ef9..18e7a89305 100644 --- a/lib/hexo/index.js +++ b/lib/hexo/index.js @@ -56,13 +56,18 @@ const createLoadThemeRoute = function(generatorResult, locals, ctx) { if (view) { log.debug(`Rendering HTML ${name}: ${magenta(path)}`); - return view.render(locals).tap(result => { - if (useCache) { - routeCache.set(generatorResult, result); - } - }).tapCatch(err => { - log.error({ err }, `Render HTML failed: ${magenta(path)}`); - }); + return view.render(locals) + .then(result => ctx.execFilter('after_route_render', result, { + context: ctx, + args: [locals] + })) + .tap(result => { + if (useCache) { + routeCache.set(generatorResult, result); + } + }).tapCatch(err => { + log.error({ err }, `Render HTML failed: ${magenta(path)}`); + }); } } diff --git a/lib/plugins/filter/after_render/index.js b/lib/plugins/filter/after_render/index.js index 819e0490ce..655e4102e4 100644 --- a/lib/plugins/filter/after_render/index.js +++ b/lib/plugins/filter/after_render/index.js @@ -3,6 +3,6 @@ module.exports = ctx => { const { filter } = ctx.extend; - filter.register('after_render:html', require('./external_link')); - filter.register('after_render:html', require('./meta_generator')); + filter.register('after_route_render', require('./external_link')); + filter.register('after_route_render', require('./meta_generator')); }; diff --git a/test/scripts/hexo/hexo.js b/test/scripts/hexo/hexo.js index c9668f5274..dd960b2d8c 100644 --- a/test/scripts/hexo/hexo.js +++ b/test/scripts/hexo/hexo.js @@ -418,6 +418,19 @@ describe('Hexo', () => { }); }); + it('_generate() - after_route_render filter', () => { + const hook = sinon.spy(result => result.replace('foo', 'bar')); + hexo.extend.filter.register('after_route_render', hook); + hexo.theme.setView('test.swig', 'foo'); + hexo.extend.generator.register('test', () => ({ + path: 'test', + layout: 'test' + })); + return hexo._generate() + .then(() => checkStream(route.get('test'), 'bar')) + .then(() => hook.called.should.be.true); + }); + it('_generate() - return nothing in generator', () => { hexo.extend.generator.register('test_nothing', () => { //