0%

文章加密

一.编辑/themes/next/layout/_partials/head.swig在如下位置添加代码

1
2
3
4
5
6
7
8
9
10
<script>
(function(){
if('{{ page.password }}'){
if (prompt('请输入密码') !== '{{ page.password }}'){
alert('密码错误');
history.back();
}
}
})();
</script>

之后,在你想要加密的文章的头文件里添加上password: xxxxxx 即可。

二.也是我自己采用的加密方法:装插件

1.npm install –save hexo-blog-encrypt

2.要为一篇文章添加密码查看功能,只需要在文章信息头部添加 password 字段即可:

1
2
3
4
5
---
title: Hello World
date: 2021-04-13 21:18:02
password: hello
---

3.在Hexo主配置文件 _config.yml 中添加如下配置:

1
2
3
4
5
6
7
8
9
# Security
encrypt: # hexo-blog-encrypt
silent: true
abstract: 这是一篇加密文章,需要密码才能继续阅读。
message: 当前文章暂不对外可见,请输入密码后查看!
tags:
- {name: private, password: hello}
wrong_pass_message: 抱歉,您输入的密码错误,请检查后重新输入。
wrong_hash_message: 抱歉, 当前文章不能被校验, 不过您还是可以看看解密后的内容。

就可以按照标签类加密

进阶教程:https://www.itfanr.cc/2021/04/16/hexo-blog-article-encryption/