0%

Hexo 命令报错

Hexo 命令报错


好友没有写博客了,今天Hexo,发现命令不可用,出现这样的错误TypeError: Cannot read property 'replace' of null

1
hexo g
2
INFO  Start processing
3
INFO  Files loaded in 627 ms
4
ERROR Render HTML failed: page/2/index.html
5
TypeError: Cannot read property 'replace' of null
6
    at Hexo.externalLinkFilter (/Users/xiaqiulei/Documents/blog/node_modules/hexo/lib/plugins/filter/after_render/external_link.js:45:15)
7
    at Hexo.tryCatcher (/Users/xiaqiulei/Documents/blog/node_modules/bluebird/js/release/util.js:16:23)
8
    at Hexo.<anonymous> (/Users/xiaqiulei/Documents/blog/node_modules/bluebird/js/release/method.js:15:34)
9
    at /Users/xiaqiulei/Documents/blog/node_modules/hexo/lib/extend/filter.js:60:50
10
    at tryCatcher (/Users/xiaqiulei/Documents/blog/node_modules/bluebird/js/release/util.js:16:23)
11
    at Object.gotValue (/Users/xiaqiulei/Documents/blog/node_modules/bluebird/js/release/reduce.js:155:18)
12
    at Object.gotAccum (/Users/xiaqiulei/Documents/blog/node_modules/bluebird/js/release/reduce.js:144:25)
13
    at Object.tryCatcher (/Users/xiaqiulei/Documents/blog/node_modules/bluebird/js/release/util.js:16:23)
14
    at Promise._settlePromiseFromHandler (/Users/xiaqiulei/Documents/blog/node_modules/bluebird/js/release/promise.js:512:31)
15
    at Promise._settlePromise (/Users/xiaqiulei/Documents/blog/node_modules/bluebird/js/release/promise.js:569:18)
16
    at Promise._settlePromiseCtx (/Users/xiaqiulei/Documents/blog/node_modules/bluebird/js/release/promise.js:606:10)
17
    at _drainQueueStep (/Users/xiaqiulei/Documents/blog/node_modules/bluebird/js/release/async.js:142:12)
18
    at _drainQueue (/Users/xiaqiulei/Documents/blog/node_modules/bluebird/js/release/async.js:131:9)
19
    at Async._drainQueues (/Users/xiaqiulei/Documents/blog/node_modules/bluebird/js/release/async.js:147:5)
20
    at Immediate.Async.drainQueues [as _onImmediate] (/Users/xiaqiulei/Documents/blog/node_modules/bluebird/js/release/async.js:17:14)
21
    at processImmediate (internal/timers.js:439:21)
22
ERROR Cannot read property 'replace' of null
23
TypeError: Cannot read property 'replace' of null
24
    at Hexo.externalLinkFilter (/Users/xiaqiulei/Documents/blog/node_modules/hexo/lib/plugins/filter/after_render/external_link.js:45:15)
25
    at Hexo.tryCatcher (/Users/xiaqiulei/Documents/blog/node_modules/bluebird/js/release/util.js:16:23)
26
    at Hexo.<anonymous> (/Users/xiaqiulei/Documents/blog/node_modules/bluebird/js/release/method.js:15:34)
27
    at /Users/xiaqiulei/Documents/blog/node_modules/hexo/lib/extend/filter.js:60:50
28
    at tryCatcher (/Users/xiaqiulei/Documents/blog/node_modules/bluebird/js/release/util.js:16:23)
29
    at Object.gotValue (/Users/xiaqiulei/Documents/blog/node_modules/bluebird/js/release/reduce.js:155:18)
30
    at Object.gotAccum (/Users/xiaqiulei/Documents/blog/node_modules/bluebird/js/release/reduce.js:144:25)
31
    at Object.tryCatcher (/Users/xiaqiulei/Documents/blog/node_modules/bluebird/js/release/util.js:16:23)
32
    at Promise._settlePromiseFromHandler (/Users/xiaqiulei/Documents/blog/node_modules/bluebird/js/release/promise.js:512:31)
33
    at Promise._settlePromise (/Users/xiaqiulei/Documents/blog/node_modules/bluebird/js/release/promise.js:569:18)
34
    at Promise._settlePromiseCtx (/Users/xiaqiulei/Documents/blog/node_modules/bluebird/js/release/promise.js:606:10)
35
    at _drainQueueStep (/Users/xiaqiulei/Documents/blog/node_modules/bluebird/js/release/async.js:142:12)
36
    at _drainQueue (/Users/xiaqiulei/Documents/blog/node_modules/bluebird/js/release/async.js:131:9)
37
    at Async._drainQueues (/Users/xiaqiulei/Documents/blog/node_modules/bluebird/js/release/async.js:147:5)
38
    at Immediate.Async.drainQueues [as _onImmediate] (/Users/xiaqiulei/Documents/blog/node_modules/bluebird/js/release/async.js:17:14)
39
    at processImmediate (internal/timers.js:439:21)
40
INFO  0 files generated in 1.6 s

跟踪源码到这个文件/Users/xiaqiulei/Documents/blog/node_modules/hexo/lib/plugins/filter/after_render/external_link.js:45:15

1
function externalLinkFilter(data) {
2
  const { config } = this;
3
4
  if (typeof config.external_link === 'undefined' || typeof config.external_link === 'object' ||
5
    config.external_link === true) {
6
    config.external_link = Object.assign({
7
      enable: true,
8
      field: 'site',
9
      exclude: ''
10
    }, config.external_link);
11
  }
12
  if (config.external_link === false || config.external_link.enable === false ||
13
    config.external_link.field !== 'site') return;
14
15
  data = data.replace(/<a.*?(href=['"](.*?)['"]).*?>/gi, (str, hrefStr, href) => {
16
    if (/target=/gi.test(str) || !isExternal(href, config)) return str;
17
18
    if (/rel=/gi.test(str)) {
19
      str = str.replace(/rel="(.*?)"/gi, (relStr, rel) => {
20
        if (!rel.includes('noopenner')) relStr = relStr.replace(rel, `${rel} noopener`);
21
        return relStr;
22
      });
23
      return str.replace(hrefStr, `${hrefStr} target="_blank"`);
24
    }
25
26
    return str.replace(hrefStr, `${hrefStr} target="_blank" rel="noopener"`);
27
  });
28
29
  return data;
30
}

发现逻辑有问题,修改_config.yml,如下所示enable: false,即可解决问题。

1
external_link: # Open external links in new tab
2
  enable: false # Open external links in new tab
3
  field: site # Apply to the whole site
4
  exclude: ''
坚持原创技术分享,您的支持将鼓励我继续创作!