使用Category标签隐藏Jekyll博客文章

本文介绍了如何使用Jekyll的Category特性来隐藏博客文章,通过修改循环条件仅显示特定category(如public)的文章,以此实现对部分内容的隐私保护。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

通过简单设置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}}">&larr; Older</a>
    {% endif %}
    {% if paginator.previous_page %}
    <a class="next" href="{{paginator.previous_page_path}}">Newer &rarr;</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 %},就达到隐藏其他文章的目的了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值