probberechts / hexo-theme-cactus

:cactus: A responsive, clean and simple theme for Hexo.
https://probberechts.github.io/hexo-theme-cactus/
MIT License
3.2k stars 784 forks source link

TypeError on layout.js #300

Closed Kemuda closed 2 years ago

Kemuda commented 2 years ago

I keep getting this error, I debugged/reversed all ejs files under layout and could not figure out what went wrong. Appreciate your help!

Unhandled rejection TypeError: /Users/amber/Documents/Blog/themes/cactus/layout/layout.ejs:3
    1| <!DOCTYPE html>
    2| <html<%= config.language ? " lang=" + config.language.substring(0, 2) : ""%>>
 >> 3| <%- partial('_partial/head') %>
    4| <body class="max-width mx-auto px3 <%- theme.direction -%>">
    5|     <% if (is_post()) { %>
    6|       <%- partial('_partial/post/actions_desktop') %>

/Users/amber/Documents/Blog/themes/cactus/layout/_partial/head.ejs:66
    64|     <% } %>
    65|     <!-- mathjax -->
 >> 66|     <% if (theme.mathjax.enabled) {%>
    67|         <script type="text/x-mathjax-config">
    68|           MathJax.Hub.Config({
    69|             tex2jax: {

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

Check your configuration (_config.yml). It looks like the following lines are missing:

# Enable MathJax support for Latex
mathjax:
  enabled: false
Kemuda commented 2 years ago

@probberechts Thanks! I added lines above and the error changed to

ERROR {
  err: ReferenceError: /Users/amber/Documents/Blog/themes/cactus/layout/layout.ejs:18
      16|         <%- partial('_partial/footer') %>
      17|     </div>
   >> 18|     <%- partial('_partial/styles') %>
      19|     <%- partial('_partial/scripts') %>
      20| </body>
      21| </html>

  /Users/amber/Documents/Blog/themes/cactus/layout/_partial/styles.ejs:19
      17| <% } %>
      18|
   >> 19| <% if (isCdnEnable('font_awesome')) { %>
      20|   <%- getCdnLink('font_awesome', {preload: true}) %>
      21| <% } else { %>
      22|   <link

  isCdnEnable is not defined
      at eval (/Users/amber/Documents/Blog/themes/cactus/layout/_partial/styles.ejs:36:8)
      at styles (/Users/amber/Documents/Blog/node_modules/ejs/lib/ejs.js:682:17)
      at _View._compiledSync (/Users/amber/Documents/Blog/node_modules/hexo/lib/theme/view.js:132:24)
      at _View.renderSync (/Users/amber/Documents/Blog/node_modules/hexo/lib/theme/view.js:59:25)
      at Object.partial (/Users/amber/Documents/Blog/node_modules/hexo/lib/plugins/helper/partial.js:34:15)
      at eval (/Users/amber/Documents/Blog/themes/cactus/layout/layout.ejs:54:17)
      at layout (/Users/amber/Documents/Blog/node_modules/ejs/lib/ejs.js:682:17)
      at _View._compiled (/Users/amber/Documents/Blog/node_modules/hexo/lib/theme/view.js:136:50)
      at _View.render (/Users/amber/Documents/Blog/node_modules/hexo/lib/theme/view.js:39:17)
      at /Users/amber/Documents/Blog/node_modules/hexo/lib/theme/view.js:51:25
      at tryCatcher (/Users/amber/Documents/Blog/node_modules/bluebird/js/release/util.js:16:23)
      at Promise._settlePromiseFromHandler (/Users/amber/Documents/Blog/node_modules/bluebird/js/release/promise.js:547:31)
      at Promise._settlePromise (/Users/amber/Documents/Blog/node_modules/bluebird/js/release/promise.js:604:18)
      at Promise._settlePromise0 (/Users/amber/Documents/Blog/node_modules/bluebird/js/release/promise.js:649:10)
      at Promise._settlePromises (/Users/amber/Documents/Blog/node_modules/bluebird/js/release/promise.js:729:18)
      at _drainQueueStep (/Users/amber/Documents/Blog/node_modules/bluebird/js/release/async.js:93:12)
      at _drainQueue (/Users/amber/Documents/Blog/node_modules/bluebird/js/release/async.js:86:9)
      at Async._drainQueues (/Users/amber/Documents/Blog/node_modules/bluebird/js/release/async.js:102:5)
      at Immediate.Async.drainQueues [as _onImmediate] (/Users/amber/Documents/Blog/node_modules/bluebird/js/release/async.js:15:14)
      at processImmediate (node:internal/timers:466:21) {
    path: '/Users/amber/Documents/Blog/themes/cactus/layout/layout.ejs'
  }
probberechts commented 2 years ago

That's a similar issue. This block has to be present in the _config.yml file:

cdn:
  enable: true
  jquery: https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js
  clipboard: https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.7/clipboard.min.js
  font_awesome: https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/all.min.css
  justified_gallery_css: https://cdnjs.cloudflare.com/ajax/libs/justifiedGallery/3.8.1/css/justifiedGallery.min.css
  justified_gallery_js: https://cdnjs.cloudflare.com/ajax/libs/justifiedGallery/3.8.1/js/jquery.justifiedGallery.min.js

You cannot just remove parts from this file. See the README for instructions how you can override config settings.

Kemuda commented 2 years ago
cdn:
  enable: true
  jquery: https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js
  clipboard: https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.7/clipboard.min.js
  font_awesome: https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/all.min.css
  justified_gallery_css: https://cdnjs.cloudflare.com/ajax/libs/justifiedGallery/3.8.1/css/justifiedGallery.min.css
  justified_gallery_js: https://cdnjs.cloudflare.com/ajax/libs/justifiedGallery/3.8.1/js/jquery.justifiedGallery.min.js

This part is actually in the file. I still do not know where exactly went wrong. But i replaced the whole theme file with the raw one and rewrote the theme config file to restore the site. Now it is all good! Thanks a lot!