通过简单设置Jekyll的Category,实现隐藏部分博客文章的功能,此方法同样适用于Octopress。
首先打开你的source/index.html
文件:
---
layout: default
---
<div class="blog-index">
{% assign index = true %}
{% for post in site.posts %} <!--遍历所有post-->
{% assign content = post.content %}
<article>
{% include article.html %}
</article>
{% endfor %}
<div class="pagination">
{% if paginator.next_page %}
<a class="prev" href="{{paginator.next_page_path}}">← Older</a>
{% endif %}
{% if paginator.previous_page %}
<a class="next" href="{{paginator.previous_page_path}}">Newer →</a>
{% endif %}
</div>
</div>
<aside class="sidebar">
{% if site.blog_index_asides.size %}
{% include_array blog_index_asides %}
{% else %}
{% include_array default_asides %}
{% endif %}
</aside>
发现默认是通过{% for post in site.posts %}
来遍历所有post的,将这个循环改为:
{% for post in site.categories.你希望显示博文的category %}
这样就只会默认在首页显示特定category的文章而隐藏其他文章了。
我的习惯时把想公开的文章的category设置成public,然后{% for post in site.categories.public %}
,就达到隐藏其他文章的目的了。