Creating categories on Jekyll driven site

前端 未结 4 1299
野趣味
野趣味 2021-02-01 07:41

I\'m having a hard time understanding how to generate archive pages for each category I use on my blog. I\'d like the user to be able to click on a category and then be taken to

4条回答
  •  天涯浪人
    2021-02-01 07:57

    For github pages, you can make an archive page with

    {% for pt in site.categories %}[{{pt[0]}}](#cat-{{pt[0]}}), {% endfor %}
    
    {% for cat in site.categories %}
    {% assign nt = cat[0] %}
    
    #### {{ nt }} {#cat-{{nt}}}
    
      {% for post in site.posts %} {% for pt in post.categories %} {% if nt == pt %}
    • {{post.published}} {{ post.title }}
    • {% endif %} {% endfor %} {% endfor %}
    {% endfor %}

    On my machine, with about 200 posts it takes 3s to generate the whole site. This is because the inner if is executed categories x number_of_posts times. On the other hand, you will have an archive page without using any plugin.

提交回复
热议问题