Skip to content

Latest commit

 

History

History
217 lines (185 loc) · 7.65 KB

ReadMe.zh.md

File metadata and controls

217 lines (185 loc) · 7.65 KB

Hexo-Blog-Encrypt

npm version

English ReadMe

##什么是 Hexo-Blog-Encrypt

尝试着想一下,你写了一篇博客,但是,出于某种原因,不太希望每一个人都可以看到他。所以你常常会为这种文章设置一个密码,其他人需要输入密码才可以访问这篇博客。对于 emlog 或者 wordpress 来说,这很容易,但是对于 hexo 来说,之前并没有一个类似的功能。

所以,Hexo-Blog-Encrypt 因为这个需求而诞生了。

##线上 Demo 你可以查看 http://mikecoder.github.io/

#安装

  • 在 hexo 根目录的 package.json 中添加 '"hexo-blog-encrypt": "1.1.*"' 依赖。
  • 然后执行 npm install 命令。
  • 该插件会自动安装

#快速开始

  • 首先在 _config.yml 中启用该插件:
# Security
##
encrypt:
    enable: true
  • 然后在你的文章的头部添加上对应的字段,如 password, abstract, message
---
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.
---
  • 然后使用 hexo clean && hexo g && hexo s,来查看效果。

#具体的使用方法

###首先,你需要在 _config.yml 中启用该插件

# Security
##
encrypt:
    enable: true

###有两种方法给文章添加密码:

####比较推荐的一种方法, 在文章文件中添加:

---
title: hello world
date: 2016-03-30 21:18:02
tags:
    - fdsfadsfa
    - fdsafsdaf
password: Mike
abstract: Welcome to my blog, enter password to read.
message: Welcome to my blog, enter password to read.
---
  • password: 是该博客加密使用的密码

  • abstract: 是该博客的摘要,会显示在博客的列表页

  • message: 这个是博客查看时,密码输入框上面的描述性文字

  • 在 hexo 根木录的 _config.yml 中添加配置信息:

####之前的老版本的配置方法依旧是可行的,不过将会废除。

# Security
##
encrypt:
    enable: true
    blogs:
        - title: hello world
          password: mikemessi
          abstract: Hello
        - title: fff
          password: fff
          abstract: Hello
  • 对于标题为 hello world 的博客,设置密码为 mikemessi,对于标题为 fff 的博客,密码设置为 fff
---
title: hello world
date: 2016-03-30 21:18:02
tags:
---
  • 这边要注意,标题一定要一致(前后空格无所谓)

###对于进阶使用

  • 如果你对默认的主题不满意,或者希望修改默认的提示和摘要内容,你可以添加如下配置在 _config.yml 中。
# Security
##
encrypt:
    enable: true
    default_abstract: the content has been encrypted, enter the password to read.</br>
    default_message: Please enter the password to read.
    default_template:
                    <link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css">
                    <link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
                    <script src="//cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
                    <script src="//cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
                    <div id="security">
                        <div>
                            <div class="input-group">
                                <input type="text" class="form-control" aria-label="enter the password" id="pass"/>
                                <div class="input-group-btn">
                                    <button type="button" class="btn btn-default" onclick="decryptAES()">解密</button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div id="encrypt-blog" style="display:none">
                        {{content}}
                    </div>
  • 可以看见,和上面的配置文件对比来看,多了 default_templatedefault_abstractdefault_message 配置项。

    • default_abstract : 这个是指在文章列表页,我们看到的加密文章描述。当然这是对所有加密文章生效的。
    • default_message : 这个在文章详情页的密码输入框上方的描述性文字。
    • default_template : 这个是指在文章详情页,我们看到的输入密码阅读的模板,同理,这个也是针对所有文章的。
      • 最后的 content 显示 div 的 id 必须 是 'encrypt-blog',同时为了好看,也希望进行隐藏。
      • 同时,必须要有一个 input 输入框,id 必须是"pass",用来供用户输入密码。
      • 输入密码之后,务必要有一个触发器,用来调用 'decryptAES' 函数。样例中以 button 来触发。
  • 如果你希望对某一篇特定的文章做特殊处理,这有两种方法可以达到这个效果, 在博客的源文件添加 template 配置:

---
title: hello world
date: 2016-03-30 21:18:02
tags:
    - fdsfadsfa
    - fdsafsdaf
password: Mike
abstract: Welcome to my blog, enter password to read.
message: Welcome to my blog, enter password to read.
template:
        <link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css">
        <link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
        <script src="//cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
        <script src="//cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
        <div id="security">
            <span>密码是 "mikemessi"</span>
            <div>
                <div class="input-group">
                    <input type="text" class="form-control" aria-label="enter the password" id="pass"/>
                    <div class="input-group-btn">
                        <button type="button" class="btn btn-default" onclick="decryptAES()">解密</button>
                    </div>
                </div>
            </div>
        </div>
        <div id="encrypt-blog" style="display:none">
            {{content}}
        </div>
---
  • 原有的添加方式依旧有效,不过已经不再推荐。
# Security
##
encrypt:
    enable: true
    blogs:
        - title: hello world
          password: mikemessi
          abstract: 文章已经被加密,请在文章页输入密码查看</br>
          template:
                    <link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css">
                    <link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
                    <script src="//cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
                    <script src="//cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
                    <div id="security">
                        <span>密码是 "mikemessi"</span>
                        <div>
                            <div class="input-group">
                                <input type="text" class="form-control" aria-label="请输入密码" id="pass"/>
                                <div class="input-group-btn">
                                    <button type="button" class="btn btn-default" onclick="decryptAES()">解密</button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div id="encrypt-blog" style="display:none">
                        {{content}}
                    </div>

##TODO See TODO File

##License See LICENSE File.