hexojs / hexo

A fast, simple & powerful blog framework, powered by Node.js.
https://hexo.io
MIT License
38.86k stars 4.76k forks source link

categories.find is not a function #2379

Closed nickdesaulniers closed 7 years ago

nickdesaulniers commented 7 years ago

before you submit your issue, please delete all the example code in template

Environment Info

Node version(node -v)

v7.4.0

Your site _config.yml

The default

Your theme _config.yml

The default

Plugin version(npm ls --depth 0)

hexo-site@0.0.0 /home/nick/blog
├── hexo@3.2.2
├── hexo-generator-archive@0.1.4
├── hexo-generator-category@0.1.3
├── hexo-generator-index@0.2.0
├── hexo-generator-tag@0.2.0
├── hexo-renderer-ejs@0.2.0
├── hexo-renderer-marked@0.2.11
├── hexo-renderer-stylus@0.3.1
└── hexo-server@0.2.0

Trying to migrate my blog from octopress. Copied over the source/_posts dir, removed the video tag the parser was choking on. Now I see this:

nick@nick-Blade-Stealth:~/blog$ hexo generate
INFO  Start processing
INFO  Files loaded in 527 ms
Unhandled rejection TypeError: /home/nick/blog/themes/landscape/layout/post.ejs:1
 >> 1| <%- partial('_partial/article', {post: page, index: false}) %>

/home/nick/blog/themes/landscape/layout/_partial/article.ejs:4
    2|   <div class="article-meta">
    3|     <%- partial('post/date', {class_name: 'article-date', date_format: null}) %>
 >> 4|     <%- partial('post/category') %>
    5|   </div>
    6|   <div class="article-inner">
    7|     <%- partial('post/gallery') %>

/home/nick/blog/themes/landscape/layout/_partial/post/category.ejs:3
    1| <% if (post.categories && post.categories.length){ %>
    2|   <div class="article-category">
 >> 3|     <%- list_categories(post.categories, {
    4|       show_count: false,
    5|       class: 'article-category',
    6|       style: 'none',

#<Object> is not a function
    at Array.find (native)
    at prepareQuery (/home/nick/blog/node_modules/hexo/lib/plugins/helper/list_categories.js:34:23)
    at flatList (/home/nick/blog/node_modules/hexo/lib/plugins/helper/list_categories.js:94:5)
    at Object.listCategoriesHelper (/home/nick/blog/node_modules/hexo/lib/plugins/helper/list_categories.js:117:15)
    at Object.wrapper [as list_categories] (/home/nick/blog/node_modules/lodash/lodash.js:4968:19)
    at eval (eval at exports.compile (/home/nick/blog/node_modules/ejs/lib/ejs.js:242:14), <anonymous>:30:156)
    at eval (eval at exports.compile (/home/nick/blog/node_modules/ejs/lib/ejs.js:242:14), <anonymous>:35:66)
    at /home/nick/blog/node_modules/ejs/lib/ejs.js:255:15
    at Theme._View.View._compiledSync (/home/nick/blog/node_modules/hexo/lib/theme/view.js:122:20)
    at Theme._View.View.View.renderSync (/home/nick/blog/node_modules/hexo/lib/theme/view.js:50:21)
    at Object.partial (/home/nick/blog/node_modules/hexo/lib/plugins/helper/partial.js:42:17)
    at Object.wrapper [as partial] (/home/nick/blog/node_modules/lodash/lodash.js:4968:19)
    at eval (eval at exports.compile (/home/nick/blog/node_modules/ejs/lib/ejs.js:242:14), <anonymous>:30:389)
    at eval (eval at exports.compile (/home/nick/blog/node_modules/ejs/lib/ejs.js:242:14), <anonymous>:30:2533)
    at /home/nick/blog/node_modules/ejs/lib/ejs.js:255:15
    at Theme._View.View._compiledSync (/home/nick/blog/node_modules/hexo/lib/theme/view.js:122:20)
    at Theme._View.View.View.renderSync (/home/nick/blog/node_modules/hexo/lib/theme/view.js:50:21)
    at Object.partial (/home/nick/blog/node_modules/hexo/lib/plugins/helper/partial.js:42:17)
    at Object.wrapper [as partial] (/home/nick/blog/node_modules/lodash/lodash.js:4968:19)
    at eval (eval at exports.compile (/home/nick/blog/node_modules/ejs/lib/ejs.js:242:14), <anonymous>:30:35)
    at eval (eval at exports.compile (/home/nick/blog/node_modules/ejs/lib/ejs.js:242:14), <anonymous>:30:101)
    at /home/nick/blog/node_modules/ejs/lib/ejs.js:255:15

Seems to be printed multiple times. Are my categories not in a parse-able format?

NoahDragon commented 7 years ago

The post looks fine to me. Is that the only post in your website?

Yalhu commented 6 years ago

I have the same error: categories.find is not a function . code: {{ list_categories('ins') }} . ins is a category of level 1 . Please help @NoahDragon @nickdesaulniers . I really don't know how to use this API. Thanks!

hardywu commented 6 years ago

This happens when you put posts not in source/_posts directory. Hexo cannot generate categories variable correctly.

MaskRay commented 3 years ago

This happens when you put posts not in source/_posts directory. Hexo cannot generate categories variable correctly.

I noticed the same problem. Not having other directories under source/ looks like a fairly unfortunate limitation. How can one write non-post markdown files?

dhay commented 1 year ago

I'm seeing this issue as well when creating pages (not posts) as described here: https://hexo.io/docs/writing#Layout

My pages have a front-matter section with a category defined, the same way as my posts. Does this have anything to do with the Page (models/page.js) object not having the same "virtual" properties as the Post object (models/page.js)?