Jekyll博客显示一个类别下的帖子 [英] Jekyll blog show posts under a category

查看:137
本文介绍了Jekyll博客显示一个类别下的帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想展示来自特定类别的帖子。例如,转到网址 http://example.com/posts/programming 将列出所有帖子将编程作为他们的类别。

I want to show posts that are from a certain category. For example, going to url http://example.com/posts/programming will list all the posts that have "programming" as their category.

我的一般博客索引如下所示

My general blog index looks like below

  {% for post in site.posts %}
    <div class="post-box">
      <div class="post-title">
        <a href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a>
      </div>
      <span class="post-date">{{ post.date | date: "%b %-d, %Y" }}</span>
      <p class="post-excerpt">{{ post.excerpt }}</p>
      <div>
        {% for category in post.categories %}
          <a href="#">#{{ category }}</a>
        {% endfor %}
      </div>
    </div>
  {% endfor %}

如果Jekyll没有自动为每个类别提供特定网址,我将不得不根据给定的网址动态更改可用的帖子。我当然可以创建一个专用于每个类别的目录,然后在其中创建 index.html ,但必须有更好的方法。

If Jekyll does not automatically provide a specific url for each category, I would have to dynamically change the available posts based on the given url. I can of course create a directory dedicated to each category and then make index.html inside it, but there must be a better way.

如果有办法动态更改 {%for post in site.posts%} part to {使用javascript在some_category%} 中发布帖子的百分比。任何帮助都会很棒。

It would be perfect if there were a way to dynamically change {% for post in site.posts %} part to {% for post in posts in some_category %} with javascript. Any help would be wonderful.

推荐答案


我当然可以创建一个专用于每个类别的目录然后在其中制作index.html,但必须有更好的方法。

I can of course create a directory dedicated to each category and then make index.html inside it, but there must be a better way.

这是一个很好的方法,isn'完成很多工作,并在gh-pages上完美地工作。这正是我在自己的网站上所做的,因为我更喜欢在目录结构中按类别保存我的.md帖子,所以我只想:

This is a great way to do it, isn't much work at all and works flawlessly on gh-pages. It's exactly what I do on my own sites as I prefer to keep my .md posts filed by category in the directory structure, so I simply have:

/blog/
    /_posts/20015-01-01-my-awesome-post.md
    index.html

/labs/
    /_posts/20015-01-01-my-technical-post.md
    index.html



<我觉得维护最好不要在_posts /中有1001个帖子,而且我得到了我想要的非常永久链接结构,而不是在每个帖子前面都输入类别。

I find it preferable for maintenance to not have 1001 posts all in _posts/ and I get the pretty permalink structure I want without entering categories in each posts front-matter.

这篇关于Jekyll博客显示一个类别下的帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆