Hexo 文章加密方案

使用Hexo搭建静态博客有时候有些想给文章加上一些权限,只有指定的人才可以看,这里提供一种通过hexo-encrypt插件实现的Hexo文章的加密方案

安装与配置

hexo-encrypt的详细介绍在这里

本地安装插件:

1
npm install hexo-encrypt --save

配置:
全站文章默认不加密,只有指定的文章加密

修改站点配置文件_config.yml,在末尾添加:

1
2
3
encrypt:
enable: true
password: 2333

其中2333为默认密码,如果在文章中没有使用新密码,默认使用这个密码

文章头部的添加说明说明:

1
2
encrypt: true
enc_pwd: 123456

这篇文章使用新的指定的密码

进阶优化

替换文本框为密码框

输入密码默认是明文显示的,把源码中的文本框改为密码框即可:

编辑文件node_modules\hexo-encrypt\lib\conf_post.js,找到:

1
this.template = ' <input id="enc_pwd_input" type="text" style="' +

替换成:

1
this.template = ' <input id="enc_pwd_input" type="password" style="' +