Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

希望加个文章加密功能 #63

Closed
Directoree opened this issue Mar 28, 2019 · 4 comments
Closed

希望加个文章加密功能 #63

Directoree opened this issue Mar 28, 2019 · 4 comments

Comments

@Directoree
Copy link

因为这款主题不支持Hexo-blog-encrypt 这款插件!>_<

@ikeq
Copy link
Owner

ikeq commented Mar 28, 2019

试一下这个 #30 (comment)

@Directoree
Copy link
Author

Directoree commented Mar 29, 2019

试一下这个 #30 (comment)

emmm...原答案的链接进不去了,密码验证的函数实在是不好找😭

@ikeq
Copy link
Owner

ikeq commented Mar 29, 2019

hexo-blog-encrypt/index.js#L94, 94, 95, 96 三行代码删掉,在 layout.ejs 的 <head> 里添加:

<%- css('css/blog-encrypt') %>
<%- js('lib/crypto-js') %>
<%- js('lib/blog-encrypt') %>

@ikeq
Copy link
Owner

ikeq commented Apr 4, 2019

补充

修改 hexo-blog-encrypt

1.hexo-blog-encrypt/index.js#L94, line 94, 95, 96 删掉新增一行代码(与主题的目录解析有冲突,所以禁用目录),修改一行代码:

    data.content = data.template;
-   data.content += `<script src="${hexo.config.root}lib/crypto-js.js"></script>`;
-   data.content += `<script src="${hexo.config.root}lib/blog-encrypt.js"></script>`;
-   data.content += `<link href="${hexo.config.root}css/blog-encrypt.css" rel="stylesheet" type="text/css">`;

+   delete data.toc;
    data.more = data.abstract;
    data.excerpt = data.more;

  }
  return data;

-});
+}, 11);

2.hexo-blog-encrypt/template.html#L1, line1 删掉

- <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

3.hexo-blog-encrypt/lib/blog-encrypt.js#L113 line113 以下代码按如下修改:

// Since you decided to use jQuery.
-$(document).ready(
-  function () {
-
-    console.log('Registering Enter for decrypt.');
-    document.getElementById('pass').onkeypress = function (keyPressEvent) {
-
-      if (keyPressEvent.keyCode === 13) {
-
-        decryptAES();
-
-      }
-
-    };
-
-  }
-);
+$(document).on('keypress', '#pass', function (keyPressEvent) {
+  if (keyPressEvent.keyCode === 13)
+    decryptAES();
+})

修改主题 layout/index.ejs

+<%- js("https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js") %>
+<%- js("lib/crypto-js") %>
+<%- js("lib/blog-encrypt") %>
+<%- css("css/blog-encrypt") %>
</head>

最后

先执行 hexo clean,再执行 hexo ghexo s

如果还不行,打开 chrome 控制台,看下是不是有个 callback 什么鬼的报错了,hexo-blog-encrypt/lib/blog-encrypt.js#L33 删掉下面那行......

      // Use jquery to load some js code
      try {

        $('#encrypt-blog').html(content);

-       {callback}

      } catch(e) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants