【Hexo】4.Hexo 博客文章进行加密
安装
npm install --save hexo-blog-encrypt
1-快速使用
将“ password”添加到您的文章信息头就像这样:
password: 123456
---
2-按标签加密
1.修改文章信息头如下:
title: Hello World
tags:
- 加密文章tag
date: 2020-03-13 21:12:21
password: muyiio
abstract: 这里有东西被加密了,需要输入密码查看哦。
message: 您好,这里需要密码。
wrong_pass_message: 抱歉,这个密码看着不太对,请再试试。
wrong_hash_message: 抱歉,这个文章不能被纠正,不过您还是能看看解密后的内容。
2.对博客根目录_config添加如下字段:
# 安全
encrypt: # hexo-blog-encryptabstract: 这里有东西被加密了,需要输入密码查看哦。message: 您好, 这里需要密码.tags:- {name: tagName, password: 密码A}- {name: tagName, password: 密码B}template: <div id="hexo-blog-encrypt" data-wpm="{{hbeWrongPassMessage}}" data-whm="{{hbeWrongHashMessage}}"><div class="hbe-input-container"><input type="password" id="hbePass" placeholder="{{hbeMessage}}" /><label>{{hbeMessage}}</label><div class="bottom-line"></div></div><script id="hbeData" type="hbeData" data-hmacdigest="{{hbeHmacDigest}}">{{hbeEncryptedData}}</script></div>wrong_pass_message: 抱歉, 这个密码看着不太对, 请再试试.wrong_hash_message: 抱歉, 这个文章不能被校验, 不过您还是能看看解密后的内容.
3-TOC 文章进行加密
- 在hexo/themes/matery/layout/_partial/article.ejs找到article.ejs
- 然后找到<%post.content%>这段代码,通常在30行左右
- 使用如下的代码来替代它:
<% 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 %>