twikoojs / twikoo

💬 一个简洁、安全、免费的静态网站评论系统 | A simple, safe, free comment system.
http://twikoo.js.org
MIT License
1.51k stars 293 forks source link

建议增加功能:多长时间以前的评论不再显示链接 #647

Closed W4J1e closed 8 months ago

W4J1e commented 8 months ago

今天在龙笑天下的博客看到这回事

image

考虑到有少数博主做博客缺乏恒心,做不久就关站,域名被其他人注册后做违规网站,导致该博主之前在其他博客留下的评论变相成为了违规站点的外链。

2024.04.21 更新

使用下面开发者提供的代码时,建议把

document.querySelectorAll('a').forEach(function(aEl){

修改为

document.querySelectorAll('.tk-comments-container a').forEach(function(aEl){

原因:1.知乎跳转页会过滤掉链接 &后面的参数,对于某些需要携带参数的场景不友好,比如某些 cps 链接;2. 如果你在博客的 footer 或者 sidebar之类的地方填写了备案信息并做了跳转,在引入了 Twikoo 的页面会导致这些链接没有直接指向需要指向的地方,通常情况下首页不受影响;

imaegoo commented 8 months ago

最近不会搞,欢迎提交pull request

imaegoo commented 8 months ago

可以考虑下这个过渡方案:在评论加载完成时,替换所有外链到知乎的中转页:

twikoo.init({
  ......,
  onCommentLoaded: function () {
    console.log('评论加载完成');
    document.querySelectorAll('a').forEach(function(aEl){
      if(!aEl.href.startsWith(window.location.origin)){
        aEl.href='https://link.zhihu.com/?target='+encodeURI(aEl.href);
      }
    });
  }
});
willow-god commented 6 months ago

可以考虑下这个过渡方案:在评论加载完成时,替换所有外链到知乎的中转页:

twikoo.init({
  ......,
  onCommentLoaded: function () {
    console.log('评论加载完成');
    document.querySelectorAll('a').forEach(function(aEl){
      if(!aEl.href.startsWith(window.location.origin)){
        aEl.href='https://link.zhihu.com/?target='+encodeURI(aEl.href);
      }
    });
  }
});

您好,请问这段代码应该添加到什么位置呀?

imaegoo commented 6 months ago

@willow-god twikoo 初始化的地方。 在主题源码里搜 twikoo.init 一般能找到相应的位置。

willow-god commented 6 months ago

@willow-god twikoo 初始化的地方。 在主题源码里搜 twikoo.init 一般能找到相应的位置。

好的,谢谢您的代码,我已经找到位置并实现了

W4J1e commented 6 months ago

@imaegoo 谢谢开发者的代码,我也用上了。