惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Latest news
Latest news
G
GRAHAM CLULEY
P
Privacy International News Feed
Know Your Adversary
Know Your Adversary
N
Netflix TechBlog - Medium
C
CERT Recently Published Vulnerability Notes
O
OpenAI News
T
Tenable Blog
Attack and Defense Labs
Attack and Defense Labs
S
Schneier on Security
The GitHub Blog
The GitHub Blog
M
MIT News - Artificial intelligence
PCI Perspectives
PCI Perspectives
博客园 - 司徒正美
Microsoft Azure Blog
Microsoft Azure Blog
MyScale Blog
MyScale Blog
Martin Fowler
Martin Fowler
S
Secure Thoughts
博客园 - 三生石上(FineUI控件)
小众软件
小众软件
T
The Exploit Database - CXSecurity.com
U
Unit 42
The Register - Security
The Register - Security
Google DeepMind News
Google DeepMind News
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
WordPress大学
WordPress大学
B
Blog
Project Zero
Project Zero
NISL@THU
NISL@THU
Cloudbric
Cloudbric
TaoSecurity Blog
TaoSecurity Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
MongoDB | Blog
MongoDB | Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
I
Intezer
L
Lohrmann on Cybersecurity
Webroot Blog
Webroot Blog
P
Proofpoint News Feed
C
Check Point Blog
Schneier on Security
Schneier on Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Hugging Face - Blog
Hugging Face - Blog
I
InfoQ
Recent Commits to openclaw:main
Recent Commits to openclaw:main
T
Threatpost
Apple Machine Learning Research
Apple Machine Learning Research
Spread Privacy
Spread Privacy
The Hacker News
The Hacker News

Mo的记事簿

安知鱼主题美化及实用教程库 给群晖套件版Emby添加网络代理 保姆式Hexo博客搭建教程 类原生安卓网络和时间修复 Front-matter 的基本认识 使用fastgithub解决GitHub无法访问 主题标签 Tag Plugins 雨世界地图(简体中文) Twikoo 添加自定义表情包 abbrlink插件生成永久固定链接 终于把hexo博客整好啦~
解决网站 URL 加个 index.html 后 Twikoo 评论显示问题
MortalCat · 2024-05-26 · via Mo的记事簿

AI初始化中...

介绍自己 🐱

生成本文简介 🐈

推荐相关文章 📖

前往主页 🏠

笔记hexoTwikoo

前言

我在浏览 twikoo 评论时发现有一个评论不知道为什么在后台可以看到,在文章评论区却看不到,跳转后发现来自 posts/261f/index.html 于是便有了这个解决此问题文章

方法参考 Twikoo Github issue

问题

使用用 hexo-abbrlink 插件生成的链接格式有两种选择

1
2
3
posts/:abbrlink.html 

posts/:abbrlink

但是使用第二种不带html结尾的格式会遇到一个问题,它是可以在后面加个 index.html 的!

1
2
https://blog.xiowo.net/posts/261f/
https://blog.xiowo.net/posts/261f/index.html

这就导致两个链接都能正常指向文章

而这时问题就来了

Twikoo 是以 url 区分页面并获取评论数据的,这就导致一个文章会有两个评论数据而且互不可见,影响挺大的

解决措施

更正评论显示位置

直接修改数据表中的 urlhref 键值,或在 Twikoo 管理面板 导出评论 json 数据使用代码编辑器将相关评论中的 urlhref 字段中的index.html删除,然后重新导入(注意:导入前需要手动删除原twikoo所有评论,确保你已做好备份!!!)

解决Twikoo 评论显示问题

在 Twikoo 初始函数的时候添加

1
location.pathname.replace(/index\.html$/, ''),

Butterfly 主题可以在路径 themes\butterfly\layout\includes\third-party\comments\twikoo.pug 进行修改,其他主题找到 Twikoo 相关文件的代码中加入即可

1
2
3
4
5
6
7
8
9
10
const init = () => {
twikoo.init(Object.assign({
el: '#twikoo-wrap',
envId: '!{envId}',
+ path: location.pathname.replace(/index\.html$/, ''),
region: '!{region}',
onCommentLoaded: () => {
btf.loadLightbox(document.querySelectorAll('#twikoo .tk-content img:not(.tk-owo-emotion)'))
}
}, !{JSON.stringify(option)}))

现在即使再通过 index.html 访问文章,他请求的数据都是不带 index.html 的了,这样他响应的评论数据都是一样的了

尾声

至此问题应该算解决了

不过新站还是建议使用第一个以 .html 结尾的链接格式(主要是我不喜欢带这个结尾

头像头像

MortalCat

MortalCat's blog

本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Mo的记事簿