1 | // Copyright © 2016 TangDongxin |
||
2 | |||
3 | // Permission is hereby granted, free of charge, to any person obtaining |
||
4 | // a copy of this software and associated documentation files (the "Software"), |
||
5 | // to deal in the Software without restriction, including without limitation |
||
6 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||
7 | // and/or sell copies of the Software, and to permit persons to whom the |
||
8 | // Software is furnished to do so, subject to the following conditions: |
||
9 | |||
10 | // The above copyright notice and this permission notice shall be included |
||
11 | // in all copies or substantial portions of the Software. |
||
12 | |||
13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
||
14 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
||
15 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
||
16 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
||
17 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
||
18 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE |
||
19 | // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||
20 | |||
21 | |||
22 | var fs = require('hexo-fs'); |
||
23 | var pathFn = require('path'); |
||
24 | var CryptoJS = require("crypto-js"); |
||
25 | |||
26 | hexo.extend.filter.register("after_post_render", function (data) { |
||
0 ignored issues
–
show
|
|||
27 | // close the encrypt function |
||
28 | if (!('encrypt' in hexo.config && hexo.config.encrypt && 'enable' in hexo.config.encrypt && hexo.config.encrypt.enable)) { |
||
0 ignored issues
–
show
The variable
hexo seems to be never declared. If this is a global, consider adding a /** global: hexo */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
29 | return data; |
||
30 | } |
||
31 | if (!('default_template' in hexo.config.encrypt && hexo.config.encrypt.default_template)) { // no such template |
||
32 | hexo.config.encrypt.default_template = '<script src="//cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script> <div id="security"> <div> <div class="input-container"> <input type="password" class="form-control" id="pass" placeholder=" {{message}} "/> <label for="pass"> {{message}} </label> <div class="bottom-line"></div> </div> </div> </div> <div id="encrypt-blog" style="display:none"> {{content}} </div>'; |
||
33 | } |
||
34 | if (!('default_abstract' in hexo.config.encrypt && hexo.config.encrypt.default_abstract)) { // no read more info |
||
35 | hexo.config.encrypt.default_abstract = 'The article has been encrypted, please enter your password to view.<br>'; |
||
36 | } |
||
37 | if (!('default_message' in hexo.config.encrypt && hexo.config.encrypt.default_message)) { // no message |
||
38 | hexo.config.encrypt.default_message = 'Please enter the password to read the blog.'; |
||
39 | } |
||
40 | |||
41 | if ('password' in data && data.password) { |
||
42 | // use the blog's config first |
||
43 | console.log('encrypt the blog :' + data.title.trim()); |
||
44 | |||
45 | // store the origin data |
||
46 | data.origin = data.content; |
||
47 | data.encrypt = true; |
||
48 | |||
49 | if (!('abstract' in data && data.abstract)) { |
||
50 | data.abstract = hexo.config.encrypt.default_abstract; |
||
51 | } |
||
52 | if (!('template' in data && data.template)) { |
||
53 | data.template = hexo.config.encrypt.default_template; |
||
54 | } |
||
55 | if (!('message' in data && data.message)) { |
||
56 | data.message = hexo.config.encrypt.default_message; |
||
57 | } |
||
58 | |||
59 | data.content = escape(data.content); |
||
60 | data.content = CryptoJS.enc.Utf8.parse(data.content); |
||
61 | data.content = CryptoJS.enc.Base64.stringify(data.content); |
||
62 | data.content = CryptoJS.AES.encrypt(data.content, String(data.password)).toString(); |
||
63 | // console.log(data.content); |
||
64 | data.template = data.template.replace('{{content}}', data.content); |
||
65 | data.template = data.template.replace('{{message}}', data.message); |
||
66 | data.template = data.template.replace('{{message}}', data.message); |
||
67 | |||
68 | data.content = data.template; |
||
69 | data.content = '<script src="' + hexo.config.root + 'mcommon.js"></script>' + data.content; |
||
70 | data.content = '<script src="' + hexo.config.root + 'crypto-js.js"></script>' + data.content; |
||
71 | data.content = '<link href="' + hexo.config.root + 'style.css" rel="stylesheet" type="text/css">' + data.content; |
||
72 | |||
73 | data.more = data.abstract; |
||
74 | data.excerpt = data.more; |
||
75 | } |
||
76 | return data; |
||
77 | }); |
||
78 | |||
79 | hexo.on('exit', function() { |
||
80 | var mcommonjs = pathFn.join(pathFn.join(pathFn.join(pathFn.join(hexo.base_dir, 'node_modules'), 'hexo-blog-encrypt'), 'lib'), 'mcommon.js'); |
||
0 ignored issues
–
show
The variable
hexo seems to be never declared. If this is a global, consider adding a /** global: hexo */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
81 | fs.readFile(mcommonjs).then(function(content) { |
||
0 ignored issues
–
show
|
|||
82 | fs.copyFile(mcommonjs, pathFn.join(hexo.public_dir, 'mcommon.js')); |
||
0 ignored issues
–
show
The variable
hexo seems to be never declared. If this is a global, consider adding a /** global: hexo */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
83 | }); |
||
84 | |||
85 | var corejs = pathFn.join(pathFn.join(pathFn.join(pathFn.join(hexo.base_dir, 'node_modules'), 'hexo-blog-encrypt'), 'lib'), 'crypto-js.js'); |
||
86 | fs.readFile(corejs).then(function(content) { |
||
0 ignored issues
–
show
|
|||
87 | fs.copyFile(corejs, pathFn.join(hexo.public_dir, 'crypto-js.js')); |
||
0 ignored issues
–
show
The variable
hexo seems to be never declared. If this is a global, consider adding a /** global: hexo */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
88 | }); |
||
89 | |||
90 | var cssFile = pathFn.join(pathFn.join(pathFn.join(pathFn.join(hexo.base_dir, 'node_modules'), 'hexo-blog-encrypt'), 'lib'), 'style.css'); |
||
91 | fs.readFile(cssFile).then(function(content) { |
||
0 ignored issues
–
show
|
|||
92 | fs.copyFile(cssFile, pathFn.join(hexo.public_dir, 'style.css')); |
||
0 ignored issues
–
show
The variable
hexo seems to be never declared. If this is a global, consider adding a /** global: hexo */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
93 | }); |
||
94 | }); |
||
95 | |||
96 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.