Skip to content

Commit

Permalink
Merge f3f1704 into 667d9a0
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Jan 27, 2020
2 parents 667d9a0 + f3f1704 commit 35f8e16
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
4 changes: 2 additions & 2 deletions lib/plugins/console/render.js
Expand Up @@ -3,7 +3,7 @@
const { resolve } = require('path');
const tildify = require('tildify');
const prettyHrtime = require('pretty-hrtime');
const fs = require('hexo-fs');
const { writeFile } = require('hexo-fs');
const { cyan, magenta } = require('chalk');

function renderConsole(args) {
Expand Down Expand Up @@ -36,7 +36,7 @@ function renderConsole(args) {
const interval = prettyHrtime(process.hrtime(start));

log.info('Rendered in %s: %s -> %s', cyan(interval), magenta(tildify(src)), magenta(tildify(dest)));
return fs.writeFile(dest, result);
return writeFile(dest, result);
});
}

Expand Down
6 changes: 3 additions & 3 deletions lib/plugins/generator/asset.js
@@ -1,12 +1,12 @@
'use strict';

const fs = require('hexo-fs');
const { exists, createReadStream } = require('hexo-fs');
const Promise = require('bluebird');
const { extname } = require('path');
const { magenta } = require('chalk');

const process = (name, ctx) => {
return Promise.filter(ctx.model(name).toArray(), asset => fs.exists(asset.source).tap(exist => {
return Promise.filter(ctx.model(name).toArray(), asset => exists(asset.source).tap(exist => {
if (!exist) return asset.remove();
})).map(asset => {
const { source } = asset;
Expand All @@ -28,7 +28,7 @@ const process = (name, ctx) => {
ctx.log.error({err}, 'Asset render failed: %s', magenta(path));
});
} else {
data.data = () => fs.createReadStream(source);
data.data = () => createReadStream(source);
}

return { path, data };
Expand Down
29 changes: 14 additions & 15 deletions lib/plugins/processor/common.js
@@ -1,35 +1,34 @@
'use strict';

const { Pattern } = require('hexo-util');
const { Cache, Pattern } = require('hexo-util');
const moment = require('moment-timezone');
const micromatch = require('micromatch');
const { isMatch: _isMatch } = require('micromatch');

const cache = new Cache();

const DURATION_MINUTE = 1000 * 60;

function isMatch(path, patterns) {
if (!patterns) return false;

return micromatch.isMatch(path, patterns);
return cache.apply(`match-${path}-${patterns}`, () => _isMatch(path, patterns));
}

function isTmpFile(path) {
const last = path[path.length - 1];
return last === '%' || last === '~';
}
const isTmpFile = path => path.endsWith('%') || path.endsWith('~');

function isHiddenFile(path) {
return /(^|\/)[_.]/.test(path);
}
const isHiddenFile = path => cache.apply(`hidden-${path}`, () => /(^|\/)[_.]/.test(path));

function isExcludedFile(path, config) {
if (isTmpFile(path)) return true;
if (isMatch(path, config.exclude)) return true;
if (isHiddenFile(path) && !isMatch(path, config.include)) return true;
return false;
return cache.apply(`excluded-${path}-${config.exclude}-${config.include}`, () => {
if (isTmpFile(path)) return true;
if (isMatch(path, config.exclude)) return true;
if (isHiddenFile(path) && !isMatch(path, config.include)) return true;
return false;
});
}

exports.ignoreTmpAndHiddenFile = new Pattern(path => {
if (isTmpFile(path) || isHiddenFile(path)) return false;
if (isHiddenFile(path) || isTmpFile(path)) return false;
return true;
});

Expand Down
6 changes: 3 additions & 3 deletions lib/plugins/renderer/yaml.js
@@ -1,10 +1,10 @@
'use strict';

const yaml = require('js-yaml');
const { load } = require('js-yaml');
const { escape } = require('hexo-front-matter');

function yamlHelper(data) {
return yaml.load(escape(data.text));
function yamlHelper({ text }) {
return load(escape(text));
}

module.exports = yamlHelper;

0 comments on commit 35f8e16

Please sign in to comment.