sunwengang blog

developer | android display/graphics

  1. 1. 直接修改JS
  2. 2. Hexo插件
    1. 2.1. 安装
    2. 2.2. 站点配置文件启用该插件
    3. 2.3. 文章的头部添加上对应的字段,如 password, abstract, message

直接修改JS

存在问题:可能被破解。如果你的博客源码是存放在GitHub这样的开源库的话,那么恭喜你。别有用心之人可以通过查看你的GitHub仓库对应文章的md文件找到这个密码。

themes/next/layout/custom/head.swig
1
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

站点配置文件启用该插件

_config.yml
1
2
encrypt:
enable: true

文章的头部添加上对应的字段,如 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: 输入密码,查看文章
---

本文作者 : sunwengang
本文使用 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 协议
本文链接 : https://alonealive.github.io/Blog/2019/07/22/2019/190722-hexo-article-pass/

本文最后更新于 天前,文中所描述的信息可能已发生改变