在Jekyll驱动的网站上创建类别 [英] Creating categories on Jekyll driven site

查看:116
本文介绍了在Jekyll驱动的网站上创建类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难理解如何为我的博客上使用的每个类别生成归档页面。我希望用户能够点击一个类别,然后转到一个页面,其中列出了分配了所需类别的所有文章。

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 a page that lists out all articles with the desired category assigned.

我可以想到的唯一方法是通过在根目录中为每个类别手动创建一个特定的html文件。但我确定一定有更有活力的方式?

The only way I can think of doing it is by manually creating a specific html file for each category in the root. But I'm sure there must be a more dynamic way?

我有网站托管在github - https://github.com/sirbrad/sirbrad.github.com

I have the site hosted on github - https://github.com/sirbrad/sirbrad.github.com

提前感谢!

Brad

推荐答案

您可以使用 site.categories 数据,使用每个类别的第一个元素(这是一个数组)来获取类别名称:

You can generate a list of all the available categories by using the site.categories data, using the first element of each category (which is an array) to get the category name:

{% for cat in site.categories %}
    <li>{{ cat[0] }}</li>
{% endfor %}

您可以生成给定类别如下:

And you can generate a list of all the posts in a given category like so:

{% for post in site.categories.CATEGORY_NAME %}

似乎不可能像你所希望的那样为每个类别生成一个单独的HTML页面,但也许一个很好的妥协是生成一个单个页面包含所有类别的列表,其中每个类别包含该类别中的所有帖子。然后,您可以使用一些简单的JavaScript来隐藏每个类别中的帖子,直到选择类别名称,为每个类别提供与个人归档页面几乎相同的用户体验。

It doesn't seem possible to generate an individual HTML page for each category as you were hoping, but perhaps a good compromise would be to generate a single page containing a list of all categories, where each category contains all the posts in that category. You could then use some simple JavaScript to hide the posts in each category until the category name is selected, giving almost the same user experience as individual archive pages for each category.

这篇关于在Jekyll驱动的网站上创建类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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