美文网首页关于hexoHexoHexo-NexT
Hexo 设置首页隐藏指定文章

Hexo 设置首页隐藏指定文章

作者: 淡之梦 | 来源:发表于2018-06-13 18:24 被阅读18次

有时候我们可能只想在首页显示关于编程之类的内容,而个人日记之类的文章放在其他分类之下而不在首页显示。可以从、分类、标签、归档中查看文章。
原文地址: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"创建的文章里面的开头。
创建的文章存放在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循环迭代文章中判断文章中的属性notshow,如果不为true就打印出文章。所以在需要隐藏的文章front-matter中添加notshow:true就可以了。

添加自定义菜单

比如我想在菜单栏添加一个“阅读”选项,但又不想新建自己一个页面,于是可以直接使用分类的页面。
创建新文章的时候直接指定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

相关文章

  • Hexo 设置首页隐藏指定文章

    有时候我们可能只想在首页显示关于编程之类的内容,而个人日记之类的文章放在其他分类之下而不在首页显示。可以从、分类、...

  • Hexo博客首页显示摘要

    Hexo博客首页默认显示整篇博文 有时候文章太长不好,不利于首页加载速度和阅读体验 文章中设置显示摘要 文章内容中...

  • Hexo博文置顶

    首页生成代码 要修改hexo博客首页文章的排序,就得修改首页index文件生成的逻辑,在hexo默认插件hero-...

  • 导航栏设置和bug处理

    直接上葵花宝典 一、先来bug 1.首页导航栏需要隐藏,二级页面需要导航栏,在首页viewWillAppear设置...

  • Echarts中饼图隐藏指示线、设置指示线长度

    效果图 设置内容如下 设置指示线长度 设置指示线长度需要分别设置length和length2的大小。 隐藏对指定区...

  • 如何左右UITableviewCell分割线

    满行显示分割线 隐藏指定行的分割线 左右分割线两端距离 1.满行显示 2.隐藏指定行 隐藏前需先按1设置满行显示 ...

  • 2017年最新基于hexo搭建个人免费博客——自定义页面样式二

    前言 本篇文章继续讲解一些hexo下next主题博客样式的修改。主要内容为修改首页文章摘要样式,文章详情样式,以及...

  • hexo的使用技巧

    总结一下hexo的使用技巧 首页展示折叠 在需要折叠的地方添加 `` 指令 指令集 hexo g = hexo g...

  • hexo首页文章显示查看原文按钮

    我们常常想在首页只显示文章的概述,而不是文章的全部,用一个 阅读全文 的字样代替,要怎么做呢?如下图: 在文章中只...

  • Hexo-设置阅读全文

    最近使用Hexo搭建了自己的博客,并且使用了简洁但是强大的NexT主题。这里介绍一下NexT主题下设置在首页显示一...

网友评论

    本文标题:Hexo 设置首页隐藏指定文章

    本文链接:https://www.haomeiwen.com/subject/tkhseftx.html