Open xiaoshenmao opened 7 years ago
为什么大家提问之前不会搜索一下issue中有没有?已经有好多次了2333(:зゝ∠)
@GeekaholicLin 问题提了很多次,然而还是没有彻底解决
“标示符会自动生成带 #more的url” 这是因为你的Hexo主题有一个阅读更多,点进去,自然就有一个"#more"的hash。
“导致一篇文章初始化了两次”
这是因为你的gitment配置问题,相关内容我已经发给你了啊,将你gitment配置中的id改为id:window.location.pathname
@GeekaholicLin 感谢
@GeekaholicLin 請問在你的主題裏面,gitment 配置中的 id 要在哪一個檔案修改呢?我用了你最新的 theme 還是會發生重複初始化的狀況
@mosdeo 在gitment.swig这个文件里。
今天遇到了同样的问题,@GeekaholicLin 所说的方法能搞定绝大部分情况。
但是,如果 URL 是一个页面呢? 比如 https://exp.com/about/
呢?而这种又可能是 https://exp.com/about
,这就会导致一篇文章可能会出现初始化两次的情况。
我的最开始解决方案是这样的。id: window.location.pathname.replace(/(\/$)/g, '') + '/'
,不管末尾有没有 /
我都给去掉后再加上,当然,如果 URL 是以 .html
或者其他有尾缀的均会加上,这将会导致之前的文章可能需要重新初始化。
后来就索性直接删除最后的 /
了,不管有没有,先删了再说。
id: window.location.pathname.replace(/(\/$)/g, '')
如果之前文章的评论不重要,或者刚刚准备配置使用 GItment 的,我认为用这种比较合适。
@isecret 我在使用material
主题, 主题提供了gitment的配置, 但是还是有些不理想, 所以我最后改成了这样:
// themes/material/layout/_widget/comment/gitcomment/enter.ejs
<script>
var gitment = new Gitment({
id: <%= theme.comment.gitment_post_id %>, // 可选。默认为 location.href
// some other settings
})
gitment.render('container')
</script>
配置文件:
// themes/material/_config.yml
comment:
# useable settings
# gitment_post_id: window.location.pathname
# this will break!
gitment_post_id: window.location.pathname.replace(/(\/$)/g, '')
# other configs
如果像上面配置的话, ejs会无法识别replace而失效, 请问有什么解决方案吗?
@huangjj27 你试试这样。脑洞解析,没测试过。
<script>
var gitment = new Gitment({
id: <%= theme.comment.gitment_post_id %>.replace(/(\/$)/g, ''), // 可选。默认为 location.href
// some other settings
})
gitment.render('container')
</script>
不行的话直接粗暴点,写在 script 标签里吧。
<script>
var gitment = new Gitment({
id: window.location.pathname.replace(/(\/$)/g, ''), // 可选。默认为 location.href
// some other settings
})
gitment.render('container')
</script>
@isecret 那就不折腾了, 目前用得还可以
噶阿三
文章 标示符会自动生成带 #more的url,导致一篇文章初始化了两次,有没有好的解决办法呢?