Skip to content

Commit a8233c9

Browse files
committed
site: introduce to twikoo comment system
1 parent b1d6d9a commit a8233c9

5 files changed

Lines changed: 43 additions & 4 deletions

File tree

config/_default/params.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ showPagination = true
3333
showhero = true
3434
showTaxonomies = true
3535
showRelatedContent = true
36+
showComments = true
3637
relatedContentLimit = 5
3738
heroStyle = "background"
3839

content/pages/about/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ showDate: false
55
showReadingTime: false
66
showWordCount: false
77
showTableOfContents: false
8-
comments: false
8+
showComments: false
99
---
1010

1111
## 关于我

content/pages/links/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ showDate: false
2727
showReadingTime: false
2828
showWordCount: false
2929
showTableOfContents: false
30-
comments: false
30+
showComments: true
3131
showhero: true
3232
herostyle: background
3333
---
3434

3535
欢迎交换~
3636

37+
在评论区留言也可
38+
3739
这是我的信息:
3840

3941
- T.本秋的自留地

layouts/partials/barba.html

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,33 @@
5050
}
5151
});
5252
}
53+
54+
// ========== 新增:强制 Twikoo 重新渲染评论区 ==========
55+
if (typeof twikoo !== 'undefined') {
56+
// console.log('Twikoo 已存在,强制重新渲染评论区');
57+
// 重新调用 init 方法,让 Twikoo 重新拉取当前页面的评论
58+
twikoo.init({
59+
envId: 'https://twikoo.texsd.eu.org', // 换成你的实际地址
60+
el: '#tcomment',
61+
path: window.location.pathname,
62+
lang: 'zh-CN',
63+
});
64+
} else {
65+
// 如果 Twikoo 还没加载,就动态加载
66+
const script = document.createElement('script');
67+
script.src = 'https://cdn.jsdelivr.net/npm/twikoo@1.6.41/dist/twikoo.all.min.js';
68+
script.onload = () => {
69+
twikoo.init({
70+
envId: 'https://twikoo.texsd.eu.org',
71+
el: '#tcomment',
72+
path: window.location.pathname,
73+
lang: 'zh-CN',
74+
});
75+
};
76+
document.head.appendChild(script);
77+
}
78+
// ====================================================
79+
5380
}, 50);
54-
document.dispatchEvent(new Event('DOMContentLoaded'));
5581
});
56-
</script>
82+
</script>

layouts/partials/comments.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{{- /* 评论区 - Twikoo */ -}}
2+
<div id="tcomment"></div>
3+
<script src="https://cdn.jsdelivr.net/npm/twikoo@latest/dist/twikoo.all.min.js"></script>
4+
<script>
5+
twikoo.init({
6+
envId: 'https://twikoo.texsd.eu.org',
7+
el: '#tcomment',
8+
lang: 'zh-CN',
9+
})
10+
</script>

0 commit comments

Comments
 (0)