为何「隐藏」
嗯,单纯记录工作内容的东西,自己看看就好了,不要给这里做流量用:P好像很是勤劳的在更新一样,所以~「notshow」-这也是本次「隐藏」的关键词
参考这篇文章
步骤
- 自定义
front-matter
的参数
例如,自定义添加一个notshow参数,值为true,用来提供判断
1 2 3 4 5 6 7 8 9 10 11 12
| title: 2019-7-8-2019-7-14 date: 2019-07-16 09:57:05 categories: - 督导记录 tags: - 2019 - 6月 - 鸡汤 - tplife - 督导 notshow: true ---
|
- 修改主题的
index.swig
文件
主题可能各不一样,但是原理都差不多,原文题主用的是next主题,正好我也是,于是就省事了:)
路径:Hexo\themes\next\layout\index.swig
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| {% extends '_layout.swig' %} {% import '_macro/post.swig' as post_template %} {% import '_macro/sidebar.swig' as sidebar_template %}
{% block title %}{{ config.title }}{% if theme.index_with_subtitle and config.subtitle %} - {{config.subtitle }}{% endif %}{% endblock %}
{% block page_class %} {% if is_home() %}page-home{% endif -%} {% endblock %}
{% block content %} <section id="posts" class="posts-expand"> {% for post in page.posts %} {{ post_template.render(post, true) }} {% endfor %} </section>
{% include '_partials/pagination.swig' %} {% endblock %}
{% block sidebar %} {{ sidebar_template.render(false) }} {% endblock %}
|
需要修改的地方如下:
1 2 3 4 5 6 7 8 9
| {% block content %} <section id="posts" class="posts-expand"> {% for post in page.posts %} {{ post_template.render(post, true) }} {% endfor %} </section>
{% include '_partials/pagination.swig' %} {% endblock %
|
添加内容是:
1 2 3
| {% if post.notshow != true %} {{ post_template.render(post, true) }} {% endif %}
|
嗯哼,于是乎修改后的全部内容如下:
1 2 3 4 5 6 7 8 9 10 11
| {% block content %} <section id="posts" class="posts-expand"> {% for post in page.posts %} {% if post.notshow != true %} {{ post_template.render(post, true) }} {% endif %} {% endfor %} </section>
{% include '_partials/pagination.swig' %} {% endblock %}
|
题主解释的是,在for循环迭代斩文章中判断文章中的属性notshow,如果不为true就打印出文章。所以在需要隐藏的文章front-matter中添加notshow:true就可以了。