有時(shí)候我們可能只想在首頁(yè)顯示關(guān)于編程之類的內(nèi)容,而個(gè)人日記之類的文章放在其他分類之下而不在首頁(yè)顯示??梢詮?、分類、標(biāo)簽、歸檔中查看文章。
原文地址:Hexo 設(shè)置首頁(yè)隱藏指定文章
自定義front-matter的參數(shù)
例如,自定義添加一個(gè)notshow參數(shù),值為true,用來提供判斷
---
title: 《好好學(xué)習(xí)》—黃金思維圈
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就可以了。
添加自定義菜單
比如我想在菜單欄添加一個(gè)“閱讀”選項(xiàng),但又不想新建自己一個(gè)頁(yè)面,于是可以直接使用分類的頁(yè)面。
創(chuàng)建新文章的時(shí)候直接指定categories: read配置
---
title: 《好好學(xué)習(xí)》—黃金思維圈
date: 2018-06-12 11:45:43
tags:
- read
categories:
- read
notshow: true
---
在git中使用hexo g命令,hexo會(huì)在根目錄/public/categrises下自動(dòng)生成分類中的閱讀文件夾
然后,
配置主題配置文件themes/_config.yml中添加以下代碼(#號(hào)后為注釋內(nèi)容)
menu:
home: / || home
about: /about/ || user
tags: /tags/ || tags
categories: /categories/ || th
read: /categories/read #指定分類中閱讀的路徑
image