added ai评论
This commit is contained in:
1 parent
ec6f05539e
commit
0f7be7d270
152 files changed
+2323
-1277
No files matched your search
@@ -21,25 +21,32 @@
|
||||
<!-- JS -->
|
||||
<!-- <script src="/js/Artalk.js"></script> -->
|
||||
<script>
|
||||
// 等待 DOM 加载完成,确保 Artalk.js (在 footer 的 bundle.js 中) 已加载
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
if (document.querySelector("#Comments")) {
|
||||
// 检查 Artalk 是否已定义
|
||||
if (typeof Artalk !== 'undefined') {
|
||||
var isDark = document.documentElement.getAttribute('data-theme') === 'dark';
|
||||
// 保存实例到全局变量 window.artalk
|
||||
window.artalk = Artalk.init({
|
||||
el: '#Comments',
|
||||
server: '{{ .Site.Params.artalk.server }}',
|
||||
site: '{{ .Site.Params.artalk.site }}',
|
||||
pageKey: '{{ .RelPermalink }}',
|
||||
flatMode: true,
|
||||
darkMode: isDark,
|
||||
emoticons: '{{ .Site.Params.artalk.emoticons | relURL }}'
|
||||
});
|
||||
} else {
|
||||
console.error('Artalk is not defined. Bundle js may not be loaded yet.');
|
||||
}
|
||||
// Configuration for Artalk and AI Comment
|
||||
window.artalkConfig = {
|
||||
el: '#Comments',
|
||||
server: '{{ .Site.Params.artalk.server }}',
|
||||
site: '{{ .Site.Params.artalk.site }}',
|
||||
pageKey: '{{ .RelPermalink }}',
|
||||
emoticons: '{{ .Site.Params.artalk.emoticons | relURL }}',
|
||||
aiComment: {{ if .Params.ai_comment }}
|
||||
{{ $avatar := .Site.Params.ai.avatar }}
|
||||
{{ if not $avatar }}{{ $avatar = .Site.Params.author.avatar }}{{ end }}
|
||||
{{ if not $avatar }}{{ $avatar = "https://cravatar.cn/avatar/unknown?d=mp" }}{{ end }}
|
||||
{{ dict "content" .Params.ai_comment "avatar" $avatar "name" (.Site.Params.ai.name | default "AI Assistant") "date" (.Date.Format "2006-01-02") | jsonify | safeJS }}
|
||||
{{ else }}null{{ end }}
|
||||
};
|
||||
|
||||
// Execute Initialization immediately if function exists (PJAX re-execution),
|
||||
// otherwise wait for DOMContentLoaded (Initial load)
|
||||
(function() {
|
||||
if (typeof window.initArtalk === 'function') {
|
||||
window.initArtalk();
|
||||
} else {
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
if (typeof window.initArtalk === 'function') {
|
||||
window.initArtalk();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
Reference in new issue
Block a user