Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to loop over posts in Hexo with native Jade construction

Tags:

node.js

pug

I know, that I can use something like this:

- site.posts.each(function(article){
      h2.title= article.title
      p.article= arcticle.content
- })

I feel this way wrong, because Jade has its own native construction for looping over something, but it seems not working:

each article in site.posts
     h2.title= article.title
     p.article= arcticle.content
like image 344
Aleksandr Zonov Avatar asked Feb 16 '14 13:02

Aleksandr Zonov


1 Answers

You need to do site.posts.toArray() and the loop will work fine. This had me confused for a while too and the answer on github is mostly in Chinese.

https://github.com/tommy351/hexo/issues/321

like image 125
user3005108 Avatar answered Nov 02 '22 15:11

user3005108