Skip to content

Commit

Permalink
Merge branch 'master' into htmlparser2-toc
Browse files Browse the repository at this point in the history
  • Loading branch information
curbengh authored Dec 13, 2019
2 parents 9db2c04 + e4a5292 commit 3906d54
Show file tree
Hide file tree
Showing 42 changed files with 520 additions and 183 deletions.
5 changes: 1 addition & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"extends": "hexo",
"root": true,
"parserOptions": {
"ecmaVersion": 2018
}
"root": true
}
40 changes: 40 additions & 0 deletions .github/getform-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,11 @@ Also, we welcome PR or issue to [official-plugins](https://github.com/hexojs).

## Sponsors

[![JetBrains](/.github/jetbrains-variant-4.svg)](https://www.jetbrains.com)
[![CMS Critic](/.github/CMS-Critic_logo-3.png)](https://www.cmscritic.com/)
<a href="https://www.jetbrains.com/"><img src="/.github/jetbrains-variant-4.svg" alt="JetBrains" width="200"/></a>

<a href="https://www.cmscritic.com/"><img src="/.github/CMS-Critic_logo-3.png" alt="CMS Critic" width="200"/></a>

<a href="https://getform.io/"><img src="/.github/getform-logo.svg" alt="Getform" width="200"/></a>

## License

Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ environment:
- nodejs_version: "8"
- nodejs_version: "10"
- nodejs_version: "12"
- nodejs_version: "13"

matrix:
fast_finish: true
Expand Down
23 changes: 17 additions & 6 deletions lib/box/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const fs = require('hexo-fs');
const chalk = require('chalk');
const { EventEmitter } = require('events');
const micromatch = require('micromatch');
const ignore = ['**/themes/*/node_modules/**', '**/themes/*/.git/**'];

const defaultPattern = new Pattern(() => ({}));

Expand All @@ -29,11 +30,14 @@ function Box(ctx, base, options) {
this.watcher = null;
this.Cache = ctx.model('Cache');
this.File = this._createFileClass();
this.ignore = ctx.config.ignore;

let ignoreCfg = ignore;
if (ctx.config.ignore) {
const targets = Array.isArray(ctx.config.ignore) ? ctx.config.ignore : [ctx.config.ignore];
this.options.ignored = (this.options.ignored || []).concat(targets.map(s => toRegExp(ctx, s)).filter(x => x));
if (ctx.config.ignore.length) ignoreCfg = ignoreCfg.concat(ctx.config.ignore);
}
this.ignore = ignoreCfg;
const targets = ignoreCfg;
this.options.ignored = (this.options.ignored || []).concat(targets.map(s => toRegExp(ctx, s)).filter(x => x));
}

require('util').inherits(Box, EventEmitter);
Expand Down Expand Up @@ -119,13 +123,20 @@ Box.prototype.addProcessor = function(pattern, fn) {
Box.prototype._readDir = function(base, fn, prefix = '') {
const { ignore } = this;

if (base && ignore && ignore.length && micromatch.isMatch(base, ignore)) {
return Promise.resolve('Ignoring dir.');
if (base && ignore) {
if (ignore.length && micromatch.isMatch(base, ignore)) {
return Promise.resolve([]);
}
}

return fs.readdir(base).map(path => fs.stat(join(base, path)).then(stats => {
const fullpath = join(base, path);
if (stats.isDirectory()) {
return this._readDir(join(base, path), fn, `${prefix + path}/`);
return this._readDir(fullpath, fn, `${prefix + path}/`);
}

if (ignore && ignore.length && micromatch.isMatch(fullpath, ignore)) {
return Promise.resolve([]);
}

return this._checkFileStatus(prefix + path).then(file => fn(file).thenReturn(file));
Expand Down
8 changes: 5 additions & 3 deletions lib/hexo/default_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ module.exports = {
permalink: ':year/:month/:day/:title/',
permalink_defaults: {},
pretty_urls: {
trailing_index: true
trailing_index: true,
trailing_html: true
},
// Directory
source_dir: 'source',
Expand Down Expand Up @@ -43,7 +44,9 @@ module.exports = {
enable: true,
auto_detect: false,
line_number: true,
tab_replace: ''
tab_replace: '',
wrap: true,
hljs: false
},
// Category & Tag
default_category: 'uncategorized',
Expand All @@ -68,4 +71,3 @@ module.exports = {
// Category & Tag
meta_generator: true
};

18 changes: 15 additions & 3 deletions lib/hexo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ const resolve = require('resolve');
const full_url_for = require('../plugins/helper/full_url_for');
const { inherits } = require('util');

const { cloneDeep, debounce } = _;

const libDir = dirname(__dirname);
const dbVersion = 1;

Expand Down Expand Up @@ -73,6 +71,20 @@ const createLoadThemeRoute = function(generatorResult, locals, ctx) {
};
};

function debounce(func, wait, immediate) {
let timeout;
return function() {
const context = this;
const args = arguments;
clearTimeout(timeout);
timeout = setTimeout(() => {
timeout = null;
if (!immediate) func.apply(context, args);
}, wait);
if (immediate && !timeout) func.apply(context, args);
};
}

class Hexo {
constructor(base = process.cwd(), args = {}) {
Reflect.apply(EventEmitter, this, []);
Expand Down Expand Up @@ -109,7 +121,7 @@ class Hexo {
tag: new extend.Tag()
};

this.config = cloneDeep(defaultConfig);
this.config = Object.assign({}, defaultConfig);

this.log = logger(this.env);

Expand Down
6 changes: 4 additions & 2 deletions lib/hexo/load_config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';

const merge = require('lodash/merge');
const { sep, resolve, join, parse } = require('path');
const tildify = require('tildify');
const Theme = require('../theme');
const Source = require('./source');
const fs = require('hexo-fs');
const chalk = require('chalk');
const { deepMerge } = require('hexo-util');

module.exports = ctx => {
if (!ctx.env.init) return;
Expand All @@ -26,7 +26,9 @@ module.exports = ctx => {

ctx.log.debug('Config loaded: %s', chalk.magenta(tildify(configPath)));

config = merge(ctx.config, config);
ctx.config = deepMerge(ctx.config, config);
config = ctx.config;

ctx.config_path = configPath;

config.root = config.root.replace(/\/*$/, '/');
Expand Down
Loading

0 comments on commit 3906d54

Please sign in to comment.