Skip to content

Commit

Permalink
feat: inject permanent link to comment templates
Browse files Browse the repository at this point in the history
  • Loading branch information
Candinya committed Sep 20, 2024
1 parent 8c90ef2 commit fa06900
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 19 deletions.
4 changes: 2 additions & 2 deletions layout/_index_style/card.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@
<% if (theme.visit_count.enable_at.includes("index")) { %>
<a>
<i class="fa fa-eye"></i>
<%- __('post_meta.read_count', process_template_path(theme.visit_count.template._shared + theme.visit_count.template.index, url_for(post.path), "visit_count")) %>
<%- __('post_meta.read_count', process_template_path(theme.visit_count.template._shared + theme.visit_count.template.index, post.path, "visit_count")) %>
</a>
<% } %>
<% if (theme.comments.count.enable_at.includes("index") && post.comments) { %>
<a>
<i class="fa fa-commenting-o"></i>
<%- __('post_meta.comments_count', process_template_path(theme.comments.count.template._shared + theme.comments.count.template.index, url_for(post.path), "comments")) %>
<%- __('post_meta.comments_count', process_template_path(theme.comments.count.template._shared + theme.comments.count.template.index, post.path, "comments")) %>
</a>
<% } %>
</span>
Expand Down
4 changes: 2 additions & 2 deletions layout/_index_style/half.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@
<% if (theme.visit_count.enable_at.includes("index")) { %>
<li>
<i class="fa fa-eye"></i>
<%- __('post_meta.read_count', process_template_path(theme.visit_count.template._shared + theme.visit_count.template.index, url_for(post.path), "visit_count")) %>
<%- __('post_meta.read_count', process_template_path(theme.visit_count.template._shared + theme.visit_count.template.index, post.path, "visit_count")) %>
</li>
<% } %>
<% if (theme.comments.count.enable_at.includes("index") && post.comments) { %>
<li>
<i class="fa fa-commenting-o"></i>
<%- __('post_meta.comments_count', process_template_path(theme.comments.count.template._shared + theme.comments.count.template.index, url_for(post.path), "comments")) %>
<%- __('post_meta.comments_count', process_template_path(theme.comments.count.template._shared + theme.comments.count.template.index, post.path, "comments")) %>
</li>
<% } %>
</ul>
Expand Down
4 changes: 2 additions & 2 deletions layout/_index_style/status.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
<% if (theme.visit_count.enable_at.includes("index")) { %>
<a>
<i class="fa fa-eye"></i>
<%- __('post_meta.read_count', process_template_path(theme.visit_count.template._shared + theme.visit_count.template.index, url_for(post.path), "visit_count")) %>
<%- __('post_meta.read_count', process_template_path(theme.visit_count.template._shared + theme.visit_count.template.index, post.path, "visit_count")) %>
</a>
<% } %>
<% if (theme.comments.count.enable_at.includes("index") && post.comments) { %>
<a>
<i class="fa fa-commenting-o"></i>
<%- __('post_meta.comments_count', process_template_path(theme.comments.count.template._shared + theme.comments.count.template.index, url_for(post.path), "comments")) %>
<%- __('post_meta.comments_count', process_template_path(theme.comments.count.template._shared + theme.comments.count.template.index, post.path, "comments")) %>
</a>
<% } %>
</span>
Expand Down
2 changes: 1 addition & 1 deletion layout/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@

<% if (theme.comments.core.enable_at.includes('index')) { %>
<div class="comment-index">
<%- process_template_path(theme.comments.core.template._shared + theme.comments.core.template.index, url_for(page.path), "comments") %>
<%- process_template_path(theme.comments.core.template._shared + theme.comments.core.template.index, page.path, "comments") %>
</div>
<% } %>
2 changes: 1 addition & 1 deletion layout/page.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</div>
<% if (page.comments && theme.comments.core.enable_at.includes('page')) { %>
<div class="comment-page">
<%- process_template_path(theme.comments.core.template._shared + theme.comments.core.template.page, url_for(page.path), "comments") %>
<%- process_template_path(theme.comments.core.template._shared + theme.comments.core.template.page, page.path, "comments") %>
</div>
<% } %>
</article>
6 changes: 3 additions & 3 deletions layout/post.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
<% if (theme.visit_count.enable_at.includes("post")) { %>
<li>
<i class="fa fa-eye"></i>
<%- __('post_meta.read_count', process_template_path(theme.visit_count.template._shared + theme.visit_count.template.post, url_for(page.path), "visit_count")) %>
<%- __('post_meta.read_count', process_template_path(theme.visit_count.template._shared + theme.visit_count.template.post, page.path, "visit_count")) %>
</li>
<% } %>
<% if (page.comments && theme.comments.count.enable_at.includes("post")) { %>
<li>
<i class="fa fa-commenting-o"></i>
<%- __('post_meta.comments_count', process_template_path(theme.comments.count.template._shared + theme.comments.count.template.post, url_for(page.path), "comments")) %>
<%- __('post_meta.comments_count', process_template_path(theme.comments.count.template._shared + theme.comments.count.template.post, page.path, "comments")) %>
</li>
<% } %>
</ul>
Expand Down Expand Up @@ -100,7 +100,7 @@
<% } %>
<% if (page.comments && theme.comments.core.enable_at.includes('post')) { %>
<div class="comment-post">
<%- process_template_path(theme.comments.core.template._shared + theme.comments.core.template.post, url_for(page.path), "comments") %>
<%- process_template_path(theme.comments.core.template._shared + theme.comments.core.template.post, page.path, "comments") %>
</div>
<% } %>
</article>
28 changes: 20 additions & 8 deletions scripts/process-template.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
const { createHash } = require("crypto");

hexo.extend.helper.register("process_template_path", (template, path, type) => {
const hasher = hexo.theme.config[type].path_hasher;
const hash = createHash(hasher);
hash.update(path);
const digest = hash.digest("hex");

return template.replaceAll("$PATH_HASH", digest).replaceAll("$PATH", path);
});
hexo.extend.helper.register(
"process_template_path",
function (template, path, type) {
const url_for = hexo.extend.helper.get("url_for").bind(this);
const full_url_for = hexo.extend.helper.get("full_url_for").bind(this);

const pathWithRoot = url_for(path);
const pathFull = full_url_for(path);

const hasher = hexo.theme.config[type].path_hasher;
const hash = createHash(hasher);
hash.update(pathWithRoot);
const digest = hash.digest("hex");

return template
.replaceAll("$PATH_HASH", digest)
.replaceAll("$PATH_FULL", pathFull)
.replaceAll("$PATH", pathWithRoot);
},
);

0 comments on commit fa06900

Please sign in to comment.