Skip to content

Commit

Permalink
🎨 兼容 hexo-blog-encrypt 插件
Browse files Browse the repository at this point in the history
  • Loading branch information
zkqiang committed Jun 14, 2022
1 parent a0831c8 commit b014c7d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
18 changes: 18 additions & 0 deletions layout/_partials/plugins/encrypt.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<%
import_script(`
<script defer>
if (document.getElementById('hbePass')) {
Fluid.utils.waitElementLoaded('hbe-prefix', function() {
var hbePrefix = document.querySelector('hbe-prefix');
hbePrefix.parentElement.classList.add('markdown-body');
Fluid.utils.retry(function() {
if (Fluid.boot && Fluid.boot.refreshPlugins) {
Fluid.boot.refreshPlugins();
return true;
}
}, 100, 10);
})
}
</script>
`)
%>
13 changes: 10 additions & 3 deletions layout/post.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,25 @@ page.banner_mask_alpha = page.banner_mask_alpha || theme.post.banner_mask_alpha
<% } %>
</p>
<% } %>
<div class="markdown-body">
<% if (page.encrypt === true) { %>
<%- inject_point('postMarkdownBegin') %>
<%- page.content %>
<%- partial('_partials/plugins/encrypt') %>
<%- inject_point('postMarkdownEnd') %>
</div>
<% } else { %>
<div class="markdown-body">
<%- inject_point('postMarkdownBegin') %>
<%- page.content %>
<%- inject_point('postMarkdownEnd') %>
</div>
<% } %>
<hr/>
<div>
<%- inject_point('postMetaBottom') %>

<%- inject_point('postCopyright') %>

<% if(theme.post.prev_next.enable && !page.hide) { %>
<% if (theme.post.prev_next.enable && !page.hide) { %>
<div class="post-prevnext my-3">
<article class="post-prev col-6">
<% const prev = prev_post(page) %>
Expand Down
14 changes: 13 additions & 1 deletion source/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,19 @@ Fluid.utils = {
}
var colorCast = (0.213 * rgbArr[0]) + (0.715 * rgbArr[1]) + (0.072 * rgbArr[2]);
return colorCast === 0 || colorCast > 255 / 2 ? 1 : -1;
}
},

retry(handler, interval, times) {
if (times <= 0) {
return;
}
var next = function() {
if (--times >= 0 && !handler()) {
setTimeout(next, interval);
}
};
setTimeout(next, interval);
},

};

Expand Down

0 comments on commit b014c7d

Please sign in to comment.