zhaoo / hexo-theme-zhaoo

🐳 A simple theme for Hexo
https://www.izhaoo.com
MIT License
273 stars 72 forks source link

Cannot read property 'path' of undefined #80

Closed hcanyz closed 3 years ago

hcanyz commented 3 years ago

hexo _config.yml 中缺少

search:
  path: ''

运行时报错。

hexo version

INFO  Validating config
hexo: 5.4.0
hexo-cli: 4.2.0
os: Windows_NT 10.0.19042 win32 x64
node: 12.18.3
v8: 7.8.279.23-node.39
uv: 1.38.0
zlib: 1.2.11
brotli: 1.0.7
ares: 1.16.0
modules: 72
nghttp2: 1.41.0
napi: 6
llhttp: 2.0.4
http_parser: 2.9.3
openssl: 1.1.1g
cldr: 37.0
icu: 67.1
tz: 2019c
unicode: 13.0

error

Cannot read property 'path' of undefined
    at eval (~\themes\zhaoo\layout\_partial\head.ejs:209:31)
    at head (~\node_modules\ejs\lib\ejs.js:682:17)
    at _View._compiledSync (~\node_modules\hexo\lib\theme\view.js:132:24)
    at _View.renderSync (~\node_modules\hexo\lib\theme\view.js:59:25)
    at Object.partial (~\node_modules\hexo\lib\plugins\helper\partial.js:34:15)
    at eval (~\themes\zhaoo\layout\layout.ejs:8:17)
    at layout (~\node_modules\ejs\lib\ejs.js:682:17)
    at _View._compiled (~\node_modules\hexo\lib\theme\view.js:136:50)
    at _View.render (~\node_modules\hexo\lib\theme\view.js:39:17)
    at ~\node_modules\hexo\lib\theme\view.js:51:25
    at tryCatcher (~\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (~\node_modules\bluebird\js\release\promise.js:547:31)
    at Promise._settlePromise (~\node_modules\bluebird\js\release\promise.js:604:18)
    at Promise._settlePromise0 (~\node_modules\bluebird\js\release\promise.js:649:10)
    at Promise._settlePromises (~\node_modules\bluebird\js\release\promise.js:729:18)
    at _drainQueueStep (~\node_modules\bluebird\js\release\async.js:93:12)
    at _drainQueue (~\node_modules\bluebird\js\release\async.js:86:9)
    at Async._drainQueues (~\node_modules\bluebird\js\release\async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (~\node_modules\bluebird\js\release\async.js:15:14)
    at processImmediate (internal/timers.js:456:21)
zhaoo commented 3 years ago

已修复。我本地无法复现,只能盲调了一下,烦请老铁看看是否有问题,谢谢!

hcanyz commented 3 years ago

还是有些问题

hexo init $,主题改成你这个,跑起来就能复现了。

 {
  err: Error: ~\themes\zhaoo\layout\layout.ejs:1
   >> 1| <%- partial('_partial/head') %>
      2| <body class="lock-screen">
      3|   <%- partial('_partial/components/loading') %>
      4|   <% if (theme.navbar.enable) { %>

  Partial _partial/head does not exist. (in layout.ejs)
      at Object.partial (~\node_modules\hexo\lib\plugins\helper\partial.js:16:11)
      at eval (~\themes\zhaoo\layout\layout.ejs:8:17)
      at layout (~\node_modules\ejs\lib\ejs.js:682:17)
      at _View._compiled (~\node_modules\hexo\lib\theme\view.js:136:50)
      at _View.render (~\node_modules\hexo\lib\theme\view.js:39:17)
      at ~\node_modules\hexo\lib\theme\view.js:51:25
      at tryCatcher (~\node_modules\bluebird\js\release\util.js:16:23)
      at Promise._settlePromiseFromHandler (~\node_modules\bluebird\js\release\promise.js:547:31)
      at Promise._settlePromise (~\node_modules\bluebird\js\release\promise.js:604:18)
      at Promise._settlePromise0 (~\node_modules\bluebird\js\release\promise.js:649:10)
      at Promise._settlePromises (~\node_modules\bluebird\js\release\promise.js:729:18)
      at _drainQueueStep (~\node_modules\bluebird\js\release\async.js:93:12)
      at _drainQueue (~\node_modules\bluebird\js\release\async.js:86:9)
      at Async._drainQueues (~\node_modules\bluebird\js\release\async.js:102:5)
      at Immediate.Async.drainQueues [as _onImmediate] (~\node_modules\bluebird\js\release\async.js:15:14)
      at processImmediate (internal/timers.js:456:21) {
    path: '~\\themes\\zhaoo\\layout\\layout.ejs'
  }
} Render HTML failed: index.html
Unhandled rejection Error: ~\themes\zhaoo\layout\layout.ejs:1
 >> 1| <%- partial('_partial/head') %>
    2| <body class="lock-screen">
    3|   <%- partial('_partial/components/loading') %>
    4|   <% if (theme.navbar.enable) { %>

Partial _partial/head does not exist. (in layout.ejs)
    at Object.partial (~\node_modules\hexo\lib\plugins\helper\partial.js:16:11)
    at eval (~\themes\zhaoo\layout\layout.ejs:8:17)
    at layout (~\node_modules\ejs\lib\ejs.js:682:17)
    at _View._compiled (~\node_modules\hexo\lib\theme\view.js:136:50)
    at _View.render (~\node_modules\hexo\lib\theme\view.js:39:17)
    at ~\node_modules\hexo\lib\theme\view.js:51:25
    at tryCatcher (~\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (~\node_modules\bluebird\js\release\promise.js:547:31)
    at Promise._settlePromise (~\node_modules\bluebird\js\release\promise.js:604:18)
    at Promise._settlePromise0 (~\node_modules\bluebird\js\release\promise.js:649:10)
    at Promise._settlePromises (~\node_modules\bluebird\js\release\promise.js:729:18)
    at _drainQueueStep (~\node_modules\bluebird\js\release\async.js:93:12)
    at _drainQueue (~\node_modules\bluebird\js\release\async.js:86:9)
    at Async._drainQueues (~\node_modules\bluebird\js\release\async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (~\node_modules\bluebird\js\release\async.js:15:14)
    at processImmediate (internal/timers.js:456:21)
zhaoo commented 3 years ago

好滴。

hcanyz commented 3 years ago

~ path: '<%- config.search ? config.search.path : '' %>'

zhaoo commented 3 years ago

测试已修复。

path: '<%- config?.search?.path %>'
hcanyz commented 3 years ago

我这边还是有问题,访问页面报前面的错。 ?. 语法需要安装什么嘛?

zhaoo commented 3 years ago

那我改成你的三元语法吧。?. 是 ES7 的。

zhaoo commented 3 years ago

已修复。

hcanyz commented 3 years ago

https://github.com/zhaoo/hexo-theme-zhaoo/blob/99d5f3e8fb1c8052029bfa9b7652362f56ceeaf9/layout/_partial/head.ejs#L125 search null 时会导致编译后 json 结构错乱

search: {
        enable: false,
        path: 
}

需要改为 `''`