Skip to content

Commit

Permalink
refactor(injector): split injector from filter
Browse files Browse the repository at this point in the history
Make sure injector is executed before after_route_render
  • Loading branch information
SukkaW committed Feb 6, 2020
1 parent 789614d commit 18421ce
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 9 deletions.
5 changes: 3 additions & 2 deletions lib/hexo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ const defaultConfig = require('./default_config');
const loadDatabase = require('./load_database');
const multiConfigPath = require('./multi_config_path');
const { sync } = require('resolve');
const full_url_for = require('../plugins/helper/full_url_for');
const injectorFilter = require('../plugins/injector');
const { inherits } = require('util');
const { deepMerge } = require('hexo-util');
const { deepMerge, full_url_for } = require('hexo-util');

const libDir = dirname(__dirname);
const dbVersion = 1;
Expand Down Expand Up @@ -57,6 +57,7 @@ const createLoadThemeRoute = function(generatorResult, locals, ctx) {
if (view) {
log.debug(`Rendering HTML ${name}: ${magenta(path)}`);
return view.render(locals)
.then(result => injectorFilter.call(ctx, result, locals))
.then(result => ctx.execFilter('after_route_render', result, {
context: ctx,
args: [locals]
Expand Down
1 change: 0 additions & 1 deletion lib/plugins/filter/after_render/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ module.exports = ctx => {

filter.register('after_route_render', require('./external_link'));
filter.register('after_route_render', require('./meta_generator'));
filter.register('after_route_render', require('./injector'));
};
File renamed without changes.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"cheerio": "0.22.0",
"decache": "^4.5.1",
"eslint": "^6.0.1",
"eslint-config-hexo": "^4.1.0",
"hexo-renderer-marked": "^2.0.0",
"husky": "^3.0.0",
"lint-staged": "^9.1.0",
"mocha": "^6.0.0",
"nyc": "^15.0.0",
"resnap": "^1.0.1",
"rewire": "^4.0.1",
"sinon": "^8.0.1"
},
Expand Down
1 change: 1 addition & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('Hexo', () => {
require('./scripts/generators');
require('./scripts/helpers');
require('./scripts/hexo');
require('./scripts/injector');
require('./scripts/models');
require('./scripts/processors');
require('./scripts/renderers');
Expand Down
1 change: 0 additions & 1 deletion test/scripts/filters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ describe('Filters', () => {
require('./excerpt');
require('./external_link');
require('./i18n_locals');
require('./injector');
require('./meta_generator');
require('./new_post_path');
require('./post_permalink');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict';

const resetCache = require('resnap')();
const decache = require('decache');

describe('Injector', () => {
const Hexo = require('../../../lib/hexo');
let hexo, injectorFilter;

beforeEach(() => {
beforeEach(async () => {
await decache('../../../lib/plugins/injector');
hexo = new Hexo();
resetCache();
injectorFilter = require('../../../lib/plugins/filter/after_render/injector').bind(hexo);
injectorFilter = require('../../../lib/plugins/injector').bind(hexo);
});

const content = [
Expand Down

0 comments on commit 18421ce

Please sign in to comment.