直接修改JS
存在问题:可能被破解。如果你的博客源码是存放在GitHub这样的开源库的话,那么恭喜你。别有用心之人可以通过查看你的GitHub仓库对应文章的md文件找到这个密码。
themes/next/layout/custom/head.swig1 2 3 4 5 6 7 8 9 10 11
| #JavaScript <script> (function(){ if('{{ page.password }}'){ if (prompt('请输入密码') !== '{{ page.password }}'){ alert('密码错误'); history.back(); } } })(); </script>
|
Hexo插件
安装
npm install --save hexo-blog-encrypt
站点配置文件启用该插件
文章的头部添加上对应的字段,如 password, abstract, message
1 2 3
| password: 是该博客加密使用的密码 abstract: 是该博客的摘要,会显示在博客的列表页 message: 这个是博客查看时,密码输入框上面的描述性文字
|
1 2 3 4 5 6 7 8 9 10 11 12
| --- title: 文章加密 date: 2019-01-04T22:20:13.000Z category: 教程 tags: - 博客 - Hexo keywords: 博客文章密码 password: pass abstract: 密码:pass message: 输入密码,查看文章 ---
|