简单方法
修改源码
打开themes->next->layout->_partials->head.swig
,在标签内插上这样一段代码:
1 2 3 4 5 6 7 8 9 10 11 12 13
| <script> (function(){ if('{{ page.password }}'){ if (prompt('请输入文章密码') !== '{{ page.password }}'){ alert('密码错误!'); history.back(); } } })(); </script>
|
文章设置
在标签头写上:
password: 123456
注意需要空格!可修改模板文件。
通过以上方式,有两大弊端:
- 搜索文章中的关键字可以得到相关的内容
- 可以通过
curl
命令获得网站的源代码
通过hexo-blog-encrypt插件
github地址:https://github.com/MikeCoder/hexo-blog-encrypt
安装插件
进入hexo根目录,安装插件:npm install hexo-blog-encrypt
修改配置文件
修改根目录下的_config.yml
,添加一下内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| # Security ## encrypt: enable: true default_abstract: 内容已经加密,请输入密码后阅读!</br> default_message: 请输入密码后阅读 default_template: <script src="//cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script> <div id="security"> <div class="input-container"> <input type="password" class="form-control" id="pass" placeholder=" {{message}} " /> <label for="pass"> {{message}} </label> <div class="bottom-line"></div> </div> </div> <div id="encrypt-blog" style="display:none"> {{content}} </div>
|
文章加密
在文章头部添加对应的字段,如password
,abstract
和message
.
1 2 3 4 5 6 7 8 9
| --- title: hello world date: 2016-03-30 21:18:02 tags: - fdsafsdaf password: Mike abstract: Welcome to my blog, enter password to read. message: Welcome to my blog, enter password to read. ---
|
abstract
和message
可以不需添加,在模板文件中已经有默认配置。
修改post模板文件
在post
模板文件中添加abstract
和message
字段。