Skip to content

Commit

Permalink
refactor(ES2015): migrate ES2015 syntax (#20)
Browse files Browse the repository at this point in the history
* use let/const and arrow function
  • Loading branch information
yoshinorin authored and tomap committed Nov 12, 2018
1 parent 8640e4d commit 569bbb2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
10 changes: 5 additions & 5 deletions lib/generator.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';

var pagination = require('hexo-pagination');
const pagination = require('hexo-pagination');

module.exports = function(locals) {
var config = this.config;
var posts = locals.posts.sort(config.index_generator.order_by);
var paginationDir = config.pagination_dir || 'page';
var path = config.index_generator.path || '';
const config = this.config;
const posts = locals.posts.sort(config.index_generator.order_by);
const paginationDir = config.pagination_dir || 'page';
const path = config.index_generator.path || '';

return pagination(path, posts, {
perPage: config.index_generator.per_page,
Expand Down
44 changes: 22 additions & 22 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict';

var should = require('chai').should(); // eslint-disable-line
var Hexo = require('hexo');
const should = require('chai').should(); // eslint-disable-line
const Hexo = require('hexo');

describe('Index generator', function() {
var hexo = new Hexo(__dirname, {silent: true});
var Post = hexo.model('Post');
var generator = require('../lib/generator').bind(hexo);
var posts;
var locals;
describe('Index generator', () => {
const hexo = new Hexo(__dirname, {silent: true});
const Post = hexo.model('Post');
const generator = require('../lib/generator').bind(hexo);
let posts;
let locals;

// Default config
hexo.config.index_generator = {
Expand All @@ -25,14 +25,14 @@ describe('Index generator', function() {
locals = hexo.locals.toObject();
}));

it('pagination enabled', function() {
it('pagination enabled', () => {
hexo.config.index_generator.per_page = 2;

var result = generator(locals);
const result = generator(locals);

result.length.should.eql(2);

for (var i = 0, len = result.length; i < len; i++) {
for (let i = 0, len = result.length; i < len; i++) {
result[i].layout.should.eql(['index', 'archive']);
result[i].data.current.should.eql(i + 1);
result[i].data.base.should.eql('');
Expand Down Expand Up @@ -61,10 +61,10 @@ describe('Index generator', function() {
hexo.config.index_generator.per_page = 10;
});

it('pagination disabled', function() {
it('pagination disabled', () => {
hexo.config.index_generator.per_page = 0;

var result = generator(locals);
const result = generator(locals);

result.length.should.eql(1);

Expand All @@ -85,17 +85,17 @@ describe('Index generator', function() {
hexo.config.index_generator.per_page = 10;
});

describe('order', function() {
it('default order', function() {
var result = generator(locals);
describe('order', () => {
it('default order', () => {
const result = generator(locals);

result[0].data.posts.should.eql(posts);
});

it('custom order', function() {
it('custom order', () => {
hexo.config.index_generator.order_by = '-order';

var result = generator(locals);
let result = generator(locals);

result[0].data.posts.eq(0).source.should.eql('bar');
result[0].data.posts.eq(1).source.should.eql('baz');
Expand All @@ -113,10 +113,10 @@ describe('Index generator', function() {
delete hexo.config.index_generator.order_by;
});

it('custom order - invalid order key', function() {
it('custom order - invalid order key', () => {
hexo.config.index_generator.order_by = '-something';

var result = generator(locals);
const result = generator(locals);

result[0].data.posts.eq(0).source.should.eql('foo');
result[0].data.posts.eq(1).source.should.eql('bar');
Expand All @@ -127,11 +127,11 @@ describe('Index generator', function() {
});
});

it('custom pagination_dir', function() {
it('custom pagination_dir', () => {
hexo.config.index_generator.per_page = 1;
hexo.config.pagination_dir = 'yo';

var result = generator(locals);
const result = generator(locals);

result[0].path.should.eql('');
result[1].path.should.eql('yo/2/');
Expand Down

0 comments on commit 569bbb2

Please sign in to comment.