Hexo 設(shè)置首頁(yè)隱藏指定文章

有時(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
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容