同时支持置顶和隐藏文章的 hexo 生成器插件(hexo-generator-index-custom)

原文地址:https://blog.im0o.top/posts/3ff4be18.html

作者:0o酱

(也是我)

hexo-generator-index-custom

支持置顶与隐藏文章的 Hexo 首页生成器插件。

在官方的首页生成器的基础上添加了使用 top 置顶文章和 hide 隐藏文章的功能。

与其他插件的区别

hexo-generator-index-pin-top

在官方版本的 hexo-generator-indexPR #51 前,大多数人置顶文章的方法是使用 hexo-generator-index-pin-top 插件。

hexo-generator-index-pin-top 插件支持置顶文章,但是不支持隐藏文章。

  • 置顶文章
  • 隐藏文章

在翻源码的时候还发现了 该插件无法更改文章排序方式,排序方式固定为文章更新时间倒序。

hexo-generator-index2

在国内可以搜索到的大多数隐藏文章的教程是通过修改主题的渲染方式来实现的。

Hexo的Butterfly下如何隐藏部分文章不在首页显示 - 张洪Heo

这个方法有一个缺点,隐藏掉的文章也会占用页面的渲染个数,如果隐藏的文章过多,会影响第一页的观感。

hexo-generator-index2 支持隐藏指定 tag/categories 的文章,但是不支持直接置顶文章。

issues #12 中提到的置顶方法较为繁琐

  • 置顶文章
  • 隐藏文章
  • 显示指定的文章

hexo-generator-index

官方提供的 hexo-generator-index 支持置顶文章(PR #51 版本后),但是不支持隐藏文章。

且官方的置顶方式为:在文章配置中添加 sticky 属性,而大多数主题渲染置顶标签的方式是读取文章中的 top 属性。

使用 hexo-generator-index-pin-top 的用户也是使用的 top 属性控制置顶。

  • 置顶文章(但是不支持 top
  • 隐藏文章

使用方法

安装

首先卸载掉已经安装的 generator-index 类插件,然后安装本插件。

$ npm uninstall hexo-generator-index

$ npm install hexo-generator-index-custom --save

# or yarn

$ yarn remove hexo-generator-index

$ yarn add hexo-generator-index-custom

配置

hexo-generator-index-custom 是直接 fork 官方的 hexo-generator-index
的,所以配置方式与官方的一样。

配置说明取自官方文档

在 _config.yml 中新增或修改如下配置:

index_generator:
  path: ''
  per_page: 10
  order_by: -date
  pagination_dir: page
  • path: Root path for your blog’s index page.
    • default: “”
  • per_page: Posts displayed per page.
    • default: config.per_page as specified in the official Hexo docs (if present), otherwise 10
    • 0 disables pagination
  • order_by: Posts order.
    • default: date descending
  • pagination_dir: URL format.
    • default: ‘page’
    • awesome-page makes the URL ends with ‘awesome-page/’ for second page and beyond.

所有的配置均与官方首页生成器一样,不必修改。

使用

在文章开头的配置中添加 stickytop 参数,可以置顶文章。

sticky 的优先级比 top 高,故所有使用 sticky 都会排在 top 之前。

其值可以是 true 或数字,数字越大,文章排在越前面。

---
title: Hello World
date: 2013/7/13 20:46:25
sticky: 100
---
---
title: Hello World
date: 2013/7/13 20:46:25
top: 100
---

在文章开头的配置中添加 hide 参数,可以隐藏文章。

---
title: Hello World
date: 2013/7/13 20:46:25
hide: true
---

已知 Bug

隐藏的文章会占用总文章数量,会影响分页数量(尾页)。

真不想修了,将就用用 欢迎 PR 修复

v1.0.1 已修复(光速修复)

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

0o酱

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值