D0n9X1n / hexo-blog-encrypt

Yet, just another hexo plugin for security.
https://www.npmjs.com/package/hexo-blog-encrypt
MIT License
971 stars 101 forks source link
encrypt hexo security

hexo-blog-encrypt

GitHub release (latest SemVer including pre-releases) Build Status Scrutinizer Code Quality

中文说明

What's this

Features

Online demo

Install

Quick start


---
title: Hello World
date: 2016-03-30 21:18:02
password: hello
---

Password Priority

post's front matter > encrypt tags

Advanced settings

in post's front matter


---
title: Hello World
tags:
- encryptAsDiary
date: 2016-03-30 21:12:21
password: mikemessi
abstract: Here's something encrypted, password is required to continue reading.
message: Hey, password is required here.
wrong_pass_message: Oh, this is an invalid password. Check and try again, please.
wrong_hash_message: Oh, these decrypted content cannot be verified, but you can still have a look.
---

In _config.yml

Example

# Security
encrypt: # hexo-blog-encrypt
  abstract: Here's something encrypted, password is required to continue reading.
  message: Hey, password is required here.
  tags:
  - {name: encryptAsDiary, password: passwordA}
  - {name: encryptAsTips, password: passwordB}
  wrong_pass_message: Oh, this is an invalid password. Check and try again, please.
  wrong_hash_message: Oh, these decrypted content cannot be verified, but you can still have a look.

To disable tag encryption

Just set the password property in front matter to "".

Example:

---
title: Callback Test
date: 2019-12-21 11:54:07
tags:
    - A Tag should be encrypted
password: ""
---

Use a "" to disable tag encryption.

Config priority

post's front matter > _config.yml (in the root directory) > default

About Callback

In some blogs, some elements may not be displayed normally after decryption. This is a known issue. The current solution is to check the code in your blog to learn which functions are called when the onload event occurs. Then write these code at the end of your post. For example:

---
title: Callback Test
date: 2019-12-21 11:54:07
tags:
    - Encrypted
---

This is a blog to test Callback functions. You just need to add code at the end of your post as follows:

It will be called after the blog is decrypted.

<script>
    // add script tag and code at the end of your post
    alert("Hello World");
</script>

Demo: Callback Example.

After Decrypt Event

Thanks to @f-dong, we now will trigger a event named hexo-blog-decrypt, so you can add a call back to listen to that event.

// trigger event
var event = new Event('hexo-blog-decrypt');
window.dispatchEvent(event);

Encrypt TOC

If you has a post with TOC, you should change the code of your template. Take the default theme 'landscape' as an example:

<% if(post.toc == true){ %>
  <div id="toc-div" class="toc-article" <% if (post.encrypt == true) { %>style="display:none" <% } %>>
    <strong class="toc-title">Index</strong>
      <% if (post.encrypt == true) { %>
        <%- toc(post.origin, {list_number: true}) %>
      <% } else { %>
        <%- toc(post.content, {list_number: true}) %>
      <% } %>
  </div>
<% } %>
<%- post.content %>

Disable logging

If you want to disable the logging, you can add a silent property in _config.yml and set it to true.

# Security
encrypt: # hexo-blog-encrypt
  silent: true

This would disable the logging like INFO hexo-blog-encrypt: encrypting "{Blog Name}" based on Tag: "EncryptedTag"..

Encrypt Theme

Previously, we use template to let users modify their own themes. Turn out that it's not a simple way. So, we are introducing this feature here.

You can simply use theme in _config.yml or in header like:

In post's front matter

---
title: Theme test
date: 2019-12-21 11:54:07
tags:
    - A Tag should be encrypted
theme: xray
password: "hello"
---

In _config.yml

This would be a default one.

# Security
encrypt: # hexo-blog-encrypt
  abstract: Here's something encrypted, password is required to continue reading.
  message: Hey, password is required here.
  tags:
  - {name: encryptAsDiary, password: passwordA}
  - {name: encryptAsTips, password: passwordB}
  theme: xray
  wrong_pass_message: Oh, this is an invalid password. Check and try again, please.
  wrong_hash_message: Oh, these decrypted content cannot be verified, but you can still have a look.

Check them online, and PICK one:

License

See LICENSE file.

Thanks

Collaborator - xiazeyu