有時候我們可能只想在首頁顯示關于編程之類的內容,而個人日記之類的文章放在其他分類之下而不在首頁顯示朦佩。可以從庐氮、分類语稠、標簽、歸檔中查看文章。
原文地址:Hexo 設置首頁隱藏指定文章
自定義front-matter的參數
例如仙畦,自定義添加一個notshow參數输涕,值為true,用來提供判斷
---
title: 《好好學習》—黃金思維圈
date: 2018-06-12 11:45:43
tags:
- read
categories:
- read
notshow: true
---
front-matter就是每次hexo new "post_name"創(chuàng)建的文章里面的開頭慨畸。
創(chuàng)建的文章存放在hexo根目錄下的:source/_posts中
修改主題的index.swig
主題可能各不一樣莱坎,但原理都是一樣的,我拿我使用的next主題來示范寸士。
路徑:Hexo\themes\next\layout\index.swig
{% 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 %}
修改這里:
{% 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 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循環(huán)迭代文章中判斷文章中的屬性notshow檐什,如果不為true就打印出文章。所以在需要隱藏的文章front-matter中添加notshow:true就可以了弱卡。
添加自定義菜單
比如我想在菜單欄添加一個“閱讀”選項乃正,但又不想新建自己一個頁面,于是可以直接使用分類的頁面婶博。
創(chuàng)建新文章的時候直接指定categories: read配置
---
title: 《好好學習》—黃金思維圈
date: 2018-06-12 11:45:43
tags:
- read
categories:
- read
notshow: true
---
在git中使用hexo g命令瓮具,hexo會在根目錄/public/categrises下自動生成分類中的閱讀文件夾
然后,
配置主題配置文件themes/_config.yml中添加以下代碼(#號后為注釋內容)
menu:
home: / || home
about: /about/ || user
tags: /tags/ || tags
categories: /categories/ || th
read: /categories/read #指定分類中閱讀的路徑
image