Li4n0 6 роки тому
батько
коміт
10dac63e50
5 змінених файлів з 199 додано та 12 видалено
  1. 1 1
      CHANGELOG.md
  2. 127 0
      README-zh_CN.md
  3. 67 10
      README.md
  4. 3 0
      requirements.txt
  5. 1 1
      shortcodes/hugo-encryptor.html

+ 1 - 1
CHANGELOG.md

@@ -1,4 +1,4 @@
-# 1.0.0 (2019-03-27)
+
 
 
 

+ 127 - 0
README-zh_CN.md

@@ -0,0 +1,127 @@
+# Hugo Encryptor
+
+**Hugo-Encryptor** 是一款能够帮助作者保护文章内容的工具。它使用 AES-256 来对文章的内容进行加密,并且通过在文章中嵌入内联 `JavaScript` 代码来验证用户输入的密码是否正确。没有正确的文章密码,读者将无法看到文章的加密内容。
+
+[English Document](./README.md)
+
+[TOC]
+
+## 安装
+
+环境依赖:Python3
+
+**步骤一:下载 Hugo-Encryptor 并安装其所需要的依赖库**
+
+```
+$ git clone https://github.com/Li4n0/hugo_encryptor.git
+$ cd Hugo-Encryptor
+$ pip install -r requirements.txt
+```
+
+**步骤二:将`hugo-encryptor.py` 放入博客根目录**
+
+```
+$ cp hugo-encryptor.py /path/to/your/blog/hugo-encryptor.py
+```
+
+**步骤三:将`shortcodes/hugo-encryptor.html` 放入博客`shortcodes` 目录**
+
+```
+$ mkdir -p /path/to/your/blog/layouts/shortcodes
+$ cp shortcodes/hugo-encryptor.html /path/to/your/blog/layouts/shortcodes/hugo-encryptor.html
+```
+
+## 使用方法
+
+**步骤一:使用 `hugo-encryptor`  shortcode 标签包裹你需要加密的内容 **
+
+**注意:在`hugo-encryptor` shortcode 标签之前必须存在一段明文文字以及 \<!--more--\> 标签 **
+
+```markdown
+---
+title: "这是一篇加密文章"
+---
+
+**这里必须存在一些明文文字以及概要标签:**
+<!--more-->
+{{% hugo-encryptor "PASSWORD" %}}
+
+# 这里是你要加密的内容!
+
+这里是你要加密的内容!
+
+**别忘了闭合 `hugo-encryptor` shortcode 标签:**
+
+{{% /hugo-encryptor %}}
+```
+
+**步骤二:像之前一样生成你的网站**
+
+```
+$ hugo
+```
+
+**步骤三:进行加密**
+
+```
+$ python hugo-encryptor.py
+```
+
+在此之后所有需要加密的文章内容都被加密完成了!
+
+之后所有需要加密的文章内容都被加密完成了!
+
+## 配置
+
+虽然 **Hugo-Encryptor** 可以在没有经过任何配置的情况下正常运行,但是我们提供了一些设置,来帮助用户将 **Hugo-Encryptor **按照自己的喜好进行配置
+
+### 语言
+
+在默认情况下,**Hugo-Encryptor** 用中文作为提示信息的输出语言,通过在博客的配置文件添加`hugoEncryptorLanguage` 参数,你可以将它改变为英文输出,就像下面这样:
+
+```toml
+[params]
+ 		 ......
+  hugoEncryptorLanguage = "en-us" # or "zh-cn"
+```
+
+### 客户端存储密码的方式
+
+默认情况下,**Hugo-Encryptor** 使用 `localStorage` 在客户端存储文章密码的 md5 值。通过在博客的配置文件添加`hugoEncryptorStorage` 参数。你可以将储存方式更改为 `sessionStorage` ,就像下面这样:
+
+```toml
+[params]
+ 		 ......
+  hugoEncryptorStorage = "session" # or "local"
+```
+
+关于两种存储方式的差别:
+
+- **localStorage**:
+
+  一旦一个读者输入了正确的密码,文章的认证状态将不会过期,该用户可以在任何时间阅读这篇文章,而无需再次输入密码。除非你更改了文章的密码,或者用户清空了浏览器缓存。
+
+- **sessionStorage**:
+
+  如果一个读者输入了正确的密码,那么在他关闭浏览器之前,他可以阅读这篇文章,而无需再次输入密码
+
+  
+
+### 样式
+
+在默认情况下,**Hugo-Encryptor** 没有任何样式,但是我们为每一个可见元素都提供了类名,方便用户自己在 css 文件中为他们添加样式
+
+## 注意:
+
+- 切记一定要保证你所加密的文章的源代码是私密的。永远不要把你的博客目录发布到一个公开的仓库
+
+- 每当你生成你的站点,你都应该再一次执行`$ python hugo-encryptor` 命令来加密你想保护的文章。如果你担心你会忘记这一点,选择使用一个 shell 脚本来代替 `$ hugo` 命令是一个不错的选择,就像下面这样:
+
+  ```bash
+  #!/bin/bash
+  hugo
+  python hugo-encryptor
+  ```
+
+  
+

+ 67 - 10
README.md

@@ -1,39 +1,48 @@
 # Hugo Encryptor
 
-**Hugo-Encryptor** is a tool to protect your [Hugo](https://gohugo.io) posts. It uses AES-128 to encrypt the contents of your posts, and inserts a snippet of `<script>` code to verify whether the password is correct or not in readers' browser. Without a correct key, nobody can decrypt your private posts.
+**Hugo-Encryptor** is a tool to protect your [Hugo](https://gohugo.io) posts. It uses AES-256 to encrypt the contents of your posts, and inserts a snippet of `<script>` code to verify whether the password is correct or not in readers' browser. Without a correct key, nobody can decrypt your private posts.
+
+[中文文档](./README-zh_CN.md)
+
+[TOC]
 
 ## Installation
 
-Step 1: Install all the requirements of Hugo-Encryptor.
+Environmental dependence: Python3
+
+**Step 1: Install all the requirements of Hugo-Encryptor.**
 
+    $ git clone https://github.com/Li4n0/hugo_encryptor.git
     $ cd Hugo-Encryptor
     $ pip install -r requirements.txt
 
-Step 2: Place `hugo-encryptor.py` somewhere in the directory of your blog.
+**Step 2: Place `hugo-encryptor.py` in the root directory of your blog.**
 
     $ cp hugo-encryptor.py /path/to/your/blog/hugo-encryptor.py
 
-Step 3: Install our Hugo shortcodes file into your blog:
+**Step 3: Place `shortcodes/hugo-encryptor.html` in the shortcode directory of your blog:**
 
     $ mkdir -p /path/to/your/blog/layouts/shortcodes
     $ cp shortcodes/hugo-encryptor.html /path/to/your/blog/layouts/shortcodes/hugo-encryptor.html
 
 ## Usage
 
-A typical way to use Hugo-Encryptor has been already uploaded in [example_site](example_site).
+**Step 1: Use `hugo-encryptor` tag surround the text you want to encrypt **
 
-**Step 1: Call our `hugo-encryptor` shortcodes if you want to encrypt a very post**
+**Attention! There must be some text and the `<!--more-->` tag before the hugo-encryptor:**
 
 ```markdown
 ---
-title: This Is An Encrypted Post
+title: "This Is An Encrypted Post"
 ---
 
+**There must be some text, and the summary tag is also needed:**
+<!--more-->
 {{% hugo-encryptor "PASSWORD" %}}
 
 # You cannot see me unless you've got the password!
 
-This is the content of my private post!
+This is the content you want to encrypt!
 
 **Do remember to close the `hugo-encryptor` shortcodes tag:**
 
@@ -48,11 +57,59 @@ It may be something like:
 
 **Step 3: Get the encryption done!**
 
-    $ python hugo-encryptor.py --path /path/to/your/blog/public
+    $ python hugo-encryptor.py
 
 Then all the private posts in your `public` directory would be encrypted thoroughly, congrats!
 
+## Configuration
+
+Although the **Hugo-Encryptor** can run without any configure, we provide some settings params to help you configure **Hugo-Encryptor** to your liking.
+
+### Language
+
+As default,**Hugo-Encryptor** displays in Chinese, by adding `hugoEncryptorLanguage` param in your blog's config file, you can change the language into English. Such as below:
+
+```toml
+[params]
+ 		 ......
+  hugoEncryptorLanguage = "en-us" # or "zh-cn"
+```
+
+### The way of client password storage
+
+As default,**Hugo-Encryptor** use `localStorage` to storage the password's md5 in client. By adding `hugoEncryptorStorage` param in your blog's config file, you can change the storage method into `sessionStorage`. Such as below:
+
+```toml
+[params]
+ 		 ......
+  hugoEncryptorStorage = "session" # or "local"
+```
+
+For the difference of two storage ways:
+
+* **localStorage**:
+
+  Once a user input the correct password,the authorization status will not expire, the user can read the article at any time without having to enter the password again. Unless you change the password or the user clean his browser cache.
+
+* **sessionStorage**:
+
+  If a user input the correct password, he could read the article without having to enter the password again until the user close his browser.
+
+### Style
+
+As default, **Hugo-Encryptor** has no style,but we have already give all the visual element a class name, you can add style for them in your css files.
+
 ## Attentions
 
-* Do remember to keep the source code of your encrypted posts private. A typical way to deal with them is to ignore them by adding `content/posts/` in your `.gitignore` file.
+* Do remember to keep the source code of your encrypted posts private. Never push your blog directory into a public repository.
+
+* Every time when you generate your site, you should run `$ python hugo-encryptor` again to encrypt the posts which you want to be protected. If you are worried about you will forgot that, it's a good idea to use a shell script to take the place of  `$ hugo` ,such as below:
+
+  ```bash
+  #!/bin/bash
+  hugo
+  python hugo-encryptor
+  ```
+
+  
 

+ 3 - 0
requirements.txt

@@ -0,0 +1,3 @@
+pycrypto==2.6.1
+beautifulsoup4==4.7.1
+lxml==4.3.3

+ 1 - 1
shortcodes/hugo-encryptor.html

@@ -28,7 +28,7 @@ your content
     <input
       class="hugo-encryptor-button"
       type="button"
-      value='{{ if eq .Site.Params.hugoEncryptorLanguage "en-us" }}Submit{{ else }}提交{{ end }}'
+      value='{{ if eq .Site.Params.hugoEncryptorLanguage "en-us" }}submit{{ else }}提交{{ end }}'
       onclick="hugoDecrypt(CryptoJS.MD5(document.getElementById('hugo-encryptor-password').value).toString(),'input')"
     />
   </div>