Hugo-Encryptor 是一款能够帮助作者保护文章内容的工具。它使用 AES-256 来对文章的内容进行加密,并且通过在文章中嵌入内联 JavaScript
代码来验证读者输入的密码是否正确。没有正确的文章密码,读者将无法看到文章的加密内容。
环境依赖:Python3
$ git clone https://github.com/Li4n0/hugo_encryptor.git
$ cd hugo_encryptor
$ chmod +x hugo_encryptor.py
$ pip install -r requirements.txt
$ mkdir -p /path/to/your/blog/layouts/shortcodes
$ ln -s /absolute/path/to/hugo_encryptor/shortcodes/hugo-encryptor.html /path/to/your/blog/layouts/shortcodes/hugo-encryptor.html
$ mkdir -p /path/to/your/blog/layouts/shortcodes
$ ln -s /absolute/path/to/hugo_encryptor/shortcodes/hugo-encryptor.html /path/to/your/blog/layouts/shortcodes/hugo-encryptor.html
注意:在 hugo-encryptor
标签之前必须存在一段明文文字以及 <!--more-->
---
title: "这是一篇加密文章"
---
**这里必须存在一些明文文字以及概要标签:**
<!--more-->
{{% hugo-encryptor "PASSWORD" %}}
# 这里是你要加密的内容!
这里是你要加密的内容!
**别忘了闭合 `hugo-encryptor` shortcode 标签:**
{{% /hugo-encryptor %}}
$ hugo
注意:在重新生成之前请先将你的
public/
删除,详见 #15。
$ python /absolute/path/to/hugo_encryptor/hugo_encryptor.py
虽然 Hugo-Encryptor 可以在没有经过任何配置的情况下正常运行,但是我们提供了一些设置,来帮助用户将 Hugo-Encryptor按照自己的喜好进行配置
在默认情况下,Hugo-Encryptor 用中文作为提示信息的输出语言,通过在博客的配置文件添加hugoEncryptorLanguage
参数,你可以将它改变为英文输出,就像下面这样:
[params]
......
hugoEncryptorLanguage = "en-us" # or "zh-cn"
在默认情况下,Hugo-Encryptor 没有任何样式,但是我们为每一个可见元素都提供了类名,方便用户自己在 css 文件中为他们添加样式
-
切记一定要保证你所加密的文章的源代码是私密的。永远不要把你的博客目录发布到一个公开的仓库
-
每当你生成你的站点,你都应该再一次执行
$ python hugo-encryptor
命令来加密你想保护的文章。如果你担心你会忘记这一点,选择使用一个 shell 脚本来代替$ hugo
命令是一个不错的选择,就像下面这样:#!/bin/bash hugo python hugo-encryptor