diff --git a/layout/_index_style/card.ejs b/layout/_index_style/card.ejs index 40869e63..cdbd7b83 100644 --- a/layout/_index_style/card.ejs +++ b/layout/_index_style/card.ejs @@ -63,13 +63,13 @@ <% if (theme.visit_count.enable_at.includes("index")) { %> - <%- __('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")) %> <% } %> <% if (theme.comments.count.enable_at.includes("index") && post.comments) { %> - <%- __('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")) %> <% } %> diff --git a/layout/_index_style/half.ejs b/layout/_index_style/half.ejs index 8fd49f6c..75301189 100644 --- a/layout/_index_style/half.ejs +++ b/layout/_index_style/half.ejs @@ -50,13 +50,13 @@ <% if (theme.visit_count.enable_at.includes("index")) { %>
  • - <%- __('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")) %>
  • <% } %> <% if (theme.comments.count.enable_at.includes("index") && post.comments) { %>
  • - <%- __('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")) %>
  • <% } %> diff --git a/layout/_index_style/status.ejs b/layout/_index_style/status.ejs index 9a5ad852..78605788 100644 --- a/layout/_index_style/status.ejs +++ b/layout/_index_style/status.ejs @@ -32,13 +32,13 @@ <% if (theme.visit_count.enable_at.includes("index")) { %> - <%- __('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")) %> <% } %> <% if (theme.comments.count.enable_at.includes("index") && post.comments) { %> - <%- __('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")) %> <% } %> diff --git a/layout/index.ejs b/layout/index.ejs index a6ded859..2b2dc54e 100644 --- a/layout/index.ejs +++ b/layout/index.ejs @@ -29,6 +29,6 @@ <% if (theme.comments.core.enable_at.includes('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") %>
    <% } %> diff --git a/layout/page.ejs b/layout/page.ejs index 27df3438..db337c7b 100644 --- a/layout/page.ejs +++ b/layout/page.ejs @@ -36,7 +36,7 @@ <% if (page.comments && theme.comments.core.enable_at.includes('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") %>
    <% } %> \ No newline at end of file diff --git a/layout/post.ejs b/layout/post.ejs index 6af3657c..5ae255f1 100644 --- a/layout/post.ejs +++ b/layout/post.ejs @@ -25,13 +25,13 @@ <% if (theme.visit_count.enable_at.includes("post")) { %>
  • - <%- __('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")) %>
  • <% } %> <% if (page.comments && theme.comments.count.enable_at.includes("post")) { %>
  • - <%- __('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")) %>
  • <% } %> @@ -100,7 +100,7 @@ <% } %> <% if (page.comments && theme.comments.core.enable_at.includes('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") %>
    <% } %> \ No newline at end of file diff --git a/scripts/process-template.js b/scripts/process-template.js index ce346d01..6ee0d8e9 100644 --- a/scripts/process-template.js +++ b/scripts/process-template.js @@ -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); + }, +);