diff --git a/ReadMe.md b/ReadMe.md index b02358b..e567663 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -10,7 +10,7 @@ Hexo-Blog-Encrypt > Now let me introduce my plugin "Hexo-Blog-Encrypt". ##Live Demo -See [http://mikecoder.github.io/](http://mikecoder.github.io/2016/03/30/helloworld/) +See [http://mikecoder.github.io/](http://mikecoder.github.io/), **all passwords are *mikemessi***. #Install + Add '"hexo-blog-encrypt": "1.1.\*"' to your hexo *package.json*. @@ -31,22 +31,30 @@ encrypt: ``` --- -title: hello world +title: Hello World date: 2016-03-30 21:18:02 -tags: - - fdsfadsfa - - fasdf - - fdsafdasf - - fdasfasdf - - fff - - fsdaf - - qfdsaf - - fdsafsdaf -password: Mike +password: mikemessi abstract: Welcome to my blog, enter password to read. message: Welcome to my blog, enter password to read. --- ``` + ++ If you want to encrypt you TOC of the blog, you should add the following code to your article.ejs: + +``` +<% if(post.toc == true){ %> +
style="display:none" <% } %>> + Index + <% if (post.encrypt == true) { %> + <%- toc(post.origin, {list_number: true}) %> + <% } else { %> + <%- toc(post.content, {list_number: true}) %> + <% } %> +
+<% } %> +<%- post.content %> +``` + + Then use *hexo clean && hexo g && hexo s* to see your blog. #Detail Usage @@ -64,18 +72,9 @@ encrypt: #### The recomanded one: add password to the source blog file. ``` --- -title: hello world +title: Hello World date: 2016-03-30 21:18:02 -tags: - - fdsfadsfa - - fasdf - - fdsafdasf - - fdasfasdf - - fff - - fsdaf - - qfdsaf - - fdsafsdaf -password: Mike +password: mikemessi abstract: Welcome to my blog, enter password to read. message: Welcome to my blog, enter password to read. --- @@ -106,11 +105,31 @@ encrypt: --- title: hello world date: 2016-03-30 21:18:02 -tags: --- ``` -###For professional usage +### Encrypt TOC + +If you has a post with TOC, you should change the code of template. Use the default theme 'landscape' as an example: + ++ You should find the *article.ejs* file which is located in *hexo/themes/landscape/layout/_partial/article.ejs*. ++ Find the code like <% post.content %>, which is usually at line 30. ++ Replace the <% post.content %> with the following code block: +``` +<% if(post.toc == true){ %> +
style="display:none" <% } %>> + Index + <% if (post.encrypt == true) { %> + <%- toc(post.origin, {list_number: true}) %> + <% } else { %> + <%- toc(post.content, {list_number: true}) %> + <% } %> +
+<% } %> +<%- post.content %> +``` + +### Change Template If you are not satisfied with the default template, you can just change it to your favorite one. Just follow the following steps. @@ -154,15 +173,6 @@ If you want to make the blog special, You can add abstract and template to your --- title: hello world date: 2016-03-30 21:18:02 -tags: - - fdsfadsfa - - fasdf - - fdsafdasf - - fdasfasdf - - fff - - fsdaf - - qfdsaf - - fdsafsdaf password: Mike abstract: Welcome to my blog, enter password to read. message: Welcome to my blog, enter password to read. diff --git a/ReadMe.zh.md b/ReadMe.zh.md index ad27a33..b712bfc 100644 --- a/ReadMe.zh.md +++ b/ReadMe.zh.md @@ -12,6 +12,8 @@ Hexo-Blog-Encrypt ##线上 Demo 你可以查看 [http://mikecoder.github.io/](http://mikecoder.github.io/2016/03/30/helloworld/) +所有的密码都是 "mikemessi" + #安装 + 在 hexo 根目录的 *package.json* 中添加 '"hexo-blog-encrypt": "1.1.\*"' 依赖。 + 然后执行 *npm install* 命令。 @@ -42,6 +44,22 @@ message: Welcome to my blog, enter password to read. --- ``` ++ 如果你想对 TOC 也进行加密,则在 article.ejs 中将 TOC 的生成代码修改成如下: + +``` + <% if(post.toc == true){ %> +
style="display:none" <% } %>> + Index + <% if (post.encrypt == true) { %> + <%- toc(post.origin, {list_number: true}) %> + <% } else { %> + <%- toc(post.content, {list_number: true}) %> + <% } %> +
+ <% } %> + <%- post.content %> +``` + + 然后使用 *hexo clean && hexo g && hexo s*,来查看效果。 @@ -105,7 +123,29 @@ tags: ``` + 这边要注意,标题一定要一致(前后空格无所谓) -###对于进阶使用 + +### 对 TOC 进行加密 + +如果你有一篇文章使用了 TOC,你需要修改模板的部分代码。这里用 landscape 作为例子: + ++ 你可以在 *hexo/themes/landscape/layout/_partial/article.ejs* 找到 article.ejs。 ++ 然后找到 <% post.content %> 这段代码,通常在30行左右。 ++ 使用如下的代码来替代它: +``` +<% if(post.toc == true){ %> +
style="display:none" <% } %>> + Index + <% if (post.encrypt == true) { %> + <%- toc(post.origin, {list_number: true}) %> + <% } else { %> + <%- toc(post.content, {list_number: true}) %> + <% } %> +
+<% } %> +<%- post.content %> +``` + +### 修改加密模板 + 如果你对默认的主题不满意,或者希望修改默认的提示和摘要内容,你可以添加如下配置在 *_config.yml* 中。 diff --git a/TODO.md b/TODO.md index 5edeaa9..cebd0dc 100644 --- a/TODO.md +++ b/TODO.md @@ -2,7 +2,7 @@ 1. √ ~~Use template to create the blog page.~~ 2. √ ~~Complete the password checking.~~ 3. √ ~~Add config to the blog source instead of the total config file.~~ -4. Encrypt the TOC of the blog. +4. √ ~~Encrypt the TOC of the blog.~~ ##BUG diff --git a/index.js b/index.js index 07350ff..a582497 100644 --- a/index.js +++ b/index.js @@ -28,7 +28,6 @@ hexo.extend.filter.register("after_post_render", function (data) { if (!('encrypt' in hexo.config && hexo.config.encrypt && 'enable' in hexo.config.encrypt && hexo.config.encrypt.enable)) { return data; } - if (!('default_template' in hexo.config.encrypt && hexo.config.encrypt.default_template)) { // no such template hexo.config.encrypt.default_template = '
'; } @@ -42,6 +41,11 @@ hexo.extend.filter.register("after_post_render", function (data) { if ('password' in data && data.password) { // use the blog's config first console.log('encrypt the blog :' + data.title.trim()); + + // store the origin data + data.origin = data.content; + data.encrypt = true; + if (!('abstract' in data && data.abstract)) { data.abstract = hexo.config.encrypt.default_abstract; } @@ -57,7 +61,7 @@ hexo.extend.filter.register("after_post_render", function (data) { data.content = CryptoJS.enc.Base64.stringify(data.content); data.content = CryptoJS.AES.encrypt(data.content, data.password).toString(); data.content = data.template.replace('{{content}}', data.content); - data.content = '' + data.message + '' + data.content; + data.content = '' + data.message + '' + data.content; data.content = '' + data.content; data.content = '' + data.content; @@ -71,6 +75,11 @@ hexo.extend.filter.register("after_post_render", function (data) { for (var i = 0, len = hexo.config.encrypt.blogs.length; i < len; i++) { if ('blogs' in hexo.config.encrypt && data.title.trim() == hexo.config.encrypt.blogs[i].title.trim()) { console.log('encrypt the blog :' + data.title.trim()); + + // store the origin data + data.origin = data.content; + data.encrypt = true; + if (!hexo.config.encrypt.blogs[i].abstract) { hexo.config.encrypt.blogs[i].abstract = hexo.config.encrypt.default_abstract; } @@ -86,7 +95,7 @@ hexo.extend.filter.register("after_post_render", function (data) { data.content = CryptoJS.enc.Base64.stringify(data.content); data.content = CryptoJS.AES.encrypt(data.content, hexo.config.encrypt.blogs[i].password).toString(); data.content = hexo.config.encrypt.blogs[i].template.replace('{{content}}', data.content); - data.content = '' + hexo.config.encrypt.blogs[i].message + '' + data.content; + data.content = '' + hexo.config.encrypt.blogs[i].message + '' + data.content; data.content = '' + data.content; data.content = '' + data.content; diff --git a/lib/mcommon.js b/lib/mcommon.js index 7130809..6ae1525 100644 --- a/lib/mcommon.js +++ b/lib/mcommon.js @@ -9,9 +9,12 @@ function decryptAES() { if (content == '') { alert("密码错误!!"); } else { - document.getElementById("encrypt-blog").style.display="inline"; - document.getElementById("encrypt-blog").innerHTML = content; - document.getElementById("security").style.display="none"; + document.getElementById("encrypt-blog").style.display = "inline"; + document.getElementById("encrypt-blog").innerHTML = content; + document.getElementById("encrypt-message").style.display = "none"; + + document.getElementById("security").style.display = "none"; + document.getElementById("toc-div").style.display = "inline"; } } catch (e) { alert("密码错误!!"); diff --git a/package.json b/package.json index 9df718d..bc46cc1 100644 --- a/package.json +++ b/package.json @@ -33,5 +33,5 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, - "version": "1.1.6" + "version": "1.1.7" }