Skip to content

Commit

Permalink
refactor: drop lodash & es6 syntax for lib/theme
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Oct 27, 2019
1 parent 182fdf4 commit 0eabb60
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
9 changes: 4 additions & 5 deletions lib/theme/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
'use strict';

const { extname } = require('path');
const util = require('util');
const { inherits } = require('util');
const Box = require('../box');
const View = require('./view');
const I18n = require('hexo-i18n');
const _ = require('lodash');

function Theme(ctx) {
Reflect.apply(Box, this, [ctx, ctx.theme_dir]);
Expand All @@ -28,7 +27,7 @@ function Theme(ctx) {
languages.push('default');

this.i18n = new I18n({
languages: _(languages).compact().uniq().value()
languages: [...new Set(languages.filter(Boolean))]
});

const viewFn = function(path, data) {
Expand All @@ -38,14 +37,14 @@ function Theme(ctx) {
const _View = viewFn;
this.View = viewFn;

util.inherits(_View, View);
inherits(_View, View);

_View.prototype._theme = this;
_View.prototype._render = ctx.render;
_View.prototype._helper = ctx.extend.helper;
}

util.inherits(Theme, Box);
inherits(Theme, Box);

Theme.prototype.getView = function(path) {
// Replace backslashes on Windows
Expand Down
8 changes: 4 additions & 4 deletions lib/theme/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const { dirname, extname, join } = require('path');
const assignIn = require('lodash/assignIn');
const omit = require('lodash/omit');
const yfm = require('hexo-front-matter');
const Promise = require('bluebird');

Expand Down Expand Up @@ -61,7 +60,9 @@ View.prototype.renderSync = function(options = {}) {
};

View.prototype._buildLocals = function(locals) {
return assignIn({}, locals, omit(this.data, ['layout', '_content']), {
// eslint-disable-next-line no-unused-vars
const { layout, _content, ...data } = this.data;
return assignIn({}, locals, data, {
filename: this.source
});
};
Expand All @@ -70,8 +71,7 @@ View.prototype._bindHelpers = function(locals) {
const helpers = this._helper.list();
const keys = Object.keys(helpers);

for (let i = 0, len = keys.length; i < len; i++) {
const key = keys[i];
for (const key of keys) {
locals[key] = helpers[key].bind(locals);
}

Expand Down

0 comments on commit 0eabb60

Please sign in to comment.