0%

Hexo NexT 主题配置二

本文提到的Hexo博客配置是基于:Hexo v4.2.1 和 NexT v7.8.0。请注意版本之间存在差异!

本文是我用Hexo配置NexT主题的第二篇笔记,主要内容有以下几点:

  • 回到顶部按钮设置
  • 添加打赏功能
  • 实现代码可复制
  • 开启相关文章推荐功能(to do)
  • 添加版权信息
  • 添加图片灯箱功能
  • 文章加密设置

回到顶部按钮设置

在主题配置文件中搜索back2top,进行修改

themes\next\_config.yml
1
2
3
4
5
6
back2top:
enable: true
# Back to top in sidebar.
sidebar: false # 是否在侧边栏显示
# Scroll percent label in b2t button.
scrollpercent: true #显示百分比

添加打赏功能

修改如下主题配置文件即可:

themes\next\_config.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
# Reward (Donate)
# Front-matter variable (unsupport animation).
reward_settings:
# If true, reward will be displayed in every article by default.
enable: true
animation: false
comment: 也不知道下面这个按钮有没有用.

reward:
wechatpay: /images/wechatpay.png
alipay: /images/alipay.png
#paypal: /images/paypal.png
#bitcoin: /images/bitcoin.png

实现代码可复制

过程有点复杂,参见:Hexo NexT 代码块复制功能 ,但是我没有成功。
会有如下问题:

1
2
3
4
clipboard-use.js:8 Uncaught ReferenceError: $ is not defined
at initCopyCode (clipboard-use.js:8)
at clipboard-use.js:15
at clipboard-use.js:16

我的解决方案:
新版NexT的新功能吧,新版本NexT
在主题配置文件中搜索 copy_button 修改如下内容:

themes\next\_config.yml
1
2
3
4
5
6
7
# Add copy button on codeblock
copy_button:
enable: true
# Show text copy result.
show_result: true
# Available values: default | flat | mac
style: flat

测试代码:

hello.cpp
1
2
3
4
5
6
7
8
#include<iostream>
using namespace std;

int main()
{
cout << "hello world!" << endl;
return 0;
}

原来这么简单,害我搞了那么半天,这样子也蛮好看的!

开启相关文章推荐功能

开启相关文章推荐需要安装hexo-related-popular-posts模块,在站点根目录下使用如下命令安装模块,

1
npm install hexo-related-popular-posts --save

然后在主题配置文件中修改如下内容:

1
2
3
4
5
6
7
8
9
10
11
12
# Related popular posts
# Dependencies: https://github.com/tea3/hexo-related-popular-posts
related_posts:
enable: true
title: 相关文章推荐 #Custom header, leave empty to use the default one
display_in_home: false
params:
maxCount: 5
#PPMixingRate: 0.0
#isDate: false
#isImage: false
#isExcerpt: false

当前hexo-related-popular-posts版本4..0.0有安全漏洞,总是安装失败,等待更新

添加版权信息

打开主题配置文件,搜索creative_commons修改如下内容:

1
2
3
4
5
creative_commons:
license: by-nc-sa
sidebar: true
post: true
language: deed.zh

参考文章 : 使用Hexo的next主题,配置POST文章文末的版权信息

添加图片灯箱功能

添加灯箱功能,实现点击图片后放大聚焦图片,并支持幻灯片播放、全屏播放、缩略图、快速分享到社交媒体等,该功能由fancyBox提供,效果如下:
随便一张图

打开主题配置文件修改如下内容:

1
fancybox: true

文章加密设置

  1. 首先在博客目录下输入如下命令,安装hexo-blog-encrypt
1
npm install --save hexo-blog-encrypt
  1. 站点配置文件中添加如下内容:
1
2
3
4
encrypt:
enable: true
default_abstract: 这是我的小秘密哦!
default_message: 你知道密码吗?
  1. 在文章开头添加如下内容
1
2
3
4
5
6
7
8
9
10
11
---
title: Hello World
tags:
- 作为日记加密
date: 2016-03-30 21:12:21
password: mikemessi
abstract: 有东西被加密了, 请输入密码查看.
message: 您好, 这里需要密码.
wrong_pass_message: 抱歉, 这个密码看着不太对, 请再试试.
wrong_hash_message: 抱歉, 这个文章不能被校验, 不过您还是能看看解密后的内容.
---

我的加密测试博客

参考文章

-------- 本文结束 感谢阅读 --------