It has been 830 days since the last update, the content of the article may be outdated.

【Hexo】文章置顶滚动栏

  1. 安装插件,在博客根目录 [BlogRoot] 下打开终端,运行以下指令:

    bash
    1
    npm install hexo-butterfly-swiper --save
  2. 添加配置信息,以下为写法示例
    在站点配置文件_config.yml 或者主题配置文件_config.butterfly.yml 中添加

    yml
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    # hexo-butterfly-swiper
    # see https://akilar.top/posts/8e1264d1/
    swiper:
    enable: true # 开关
    priority: 5 #过滤器优先权
    enable_page: all # 应用页面
    timemode: date #date/updated
    layout: # 挂载容器类型
    type: id
    name: recent-posts
    index: 0
    default_descr: 再怎么看我也不知道怎么描述它的啦!
    swiper_css: https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiper.min.css #swiper css依赖
    swiper_js: https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiper.min.js #swiper js依赖
    custom_css: https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiperstyle.css # 适配主题样式补丁
    custom_js: https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiper_init.js # swiper初始化方法
  3. 参数释义

参数 备选值 / 类型 释义
priority number 【可选】过滤器优先级,数值越小,执行越早,默认为 10,选填
enable true/false 【必选】控制开关
enable_page path/all 【可选】填写想要应用的页面的相对路径(即路由地址), 如根目录就填’/‘, 分类页面就填’/categories/‘。若要应用于所有页面,就填’all’,默认为 all
timemode date/updated 【可选】时间显示,date 为显示创建日期,updated 为显示更新日期,默认为 date
layout.type id/class 【可选】挂载容器类型,填写 id 或 class,不填则默认为 id
layout.name text 【必选】挂载容器名称
layout.index 0 和正整数 【可选】前提是 layout.type 为 class,因为同一页面可能有多个 class,此项用来确认究竟排在第几个顺位
default_descr text 默认文章描述
swiper_css url 【可选】自定义的 swiper 依赖项 css 链接
swiper_js url 【可选】自定义的 swiper 依赖项加 js 链接
custom_css url 【可选】适配主题样式补丁
custom_js url 【可选】swiper 初始化方法

使用方法:在文章的 front_matter 中添加 swiper_index 配置项即可。

markdown
1
2
3
4
5
6
7
8
---
title: 文章标题
date: 创建日期
updated: 更新日期
cover: 文章封面
description: 文章描述
swiper_index: 1 #置顶轮播图顺序,非负整数,数字越大越靠前
---