Skip to content

Commit

Permalink
Merge pull request #195 from jht3QAQ/Candinya/iss139
Browse files Browse the repository at this point in the history
fix: gitalk id too long to create create issue
  • Loading branch information
Candinya authored Jan 18, 2024
2 parents 1df398c + db9ccb9 commit 897d07f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ gitalk:
- 'Candinya'
distractionFreeMode: false

#默认不计算hash 但是如果id过长(默认为url_for(page.path))会导致创建评论区失败 见[#139](https://github.com/Candinya/Kratos-Rebirth/issues/139)
gitalk_id_hasher: false
# gitalk_id_hasher: md5

# Gitment [Gitment](https://github.com/imsun/gitment/) 评论相关
## 不仅限于以下内容,您可以参照 [Gitment 文档](https://github.com/imsun/gitment#methods) 设置您需要的配置项
## id 会在页面自动生成,不必加入
Expand Down
2 changes: 1 addition & 1 deletion layout/_comments/gitalk.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
const init = () => {
console.log('Gitalk loading...');
const gitalk = new Gitalk(Object.assign({
id: '<%- url_for(page.path) %>',
id: '<%- hash_gitalk_id(url_for(page.path)) %>',
path: '<%- url_for(page.path) %>'
}, JSON.parse('<%- JSON.stringify(theme.gitalk) %>')));
Expand Down
9 changes: 9 additions & 0 deletions scripts/comments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const {createHash,} = require('crypto');

hexo.extend.helper.register("hash_gitalk_id", function(id){
const hasher = hexo.theme.config.gitalk_id_hasher;
if(!hasher)return id;
const hash = createHash(hasher);
hash.update(id);
return hash.digest('hex');
});

0 comments on commit 897d07f

Please sign in to comment.