Skip to content

Commit

Permalink
add giscus
Browse files Browse the repository at this point in the history
  • Loading branch information
jiacai2050 committed Jan 4, 2025
1 parent 63706e0 commit a9ea151
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
11 changes: 8 additions & 3 deletions book.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[book]
authors = ["ZigCC"]
authors = ["ZigCC <hello@ziglang.cc>"]
description = "Zig cookbook is a collection of simple Zig programs that demonstrate good practices to accomplish common programming tasks."
language = "en"
multilingual = false
src = "book-src"
Expand All @@ -8,10 +9,14 @@ title = "Zig cookbook"
[output.html]
git-repository-url = "https://github.com/zigcc/zig-cookbook"
edit-url-template = "https://github.com/zigcc/zig-cookbook/edit/main/{path}"
additional-js = ["static/zig-hl.js"]
additional-js = ["static/zig-hl.js", "static/giscus.js"]
additional-css = ["static/last-changed.css"]
# site-url = "zig-cookbook"

[preprocessor.last-changed]
command = "mdbook-last-changed"
renderer = ["html"]
renderer = ["html"]


[build]
create-missing = false
35 changes: 35 additions & 0 deletions static/giscus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
function appendGiscusScript() {
const pageDiv = document.querySelector('#content > main');

if (!pageDiv) {
console.error('Could not find div with class "page"');
return;
}
// 创建评论容器
const commentsDiv = document.createElement('div');
commentsDiv.className = 'giscus';
pageDiv.appendChild(commentsDiv);

// 创建 script 元素
const script = document.createElement('script');
// 设置脚本属性
script.src = "https://giscus.app/client.js";
script.setAttribute("data-repo", "zigcc/zig-cookbook");
script.setAttribute("data-repo-id", "R_kgDOK34kdA");
script.setAttribute("data-category", "General");
script.setAttribute("data-category-id", "DIC_kwDOK34kdM4Clt_g");
script.setAttribute("data-mapping", "pathname");
script.setAttribute("data-strict", "1");
script.setAttribute("data-reactions-enabled", "1");
script.setAttribute("data-emit-metadata", "0");
script.setAttribute("data-input-position", "bottom");
script.setAttribute("data-theme", "preferred_color_scheme");
script.setAttribute("data-lang", "en");
script.setAttribute("crossorigin", "anonymous");
script.async = true;

// 将脚本追加到 body 末尾
pageDiv.appendChild(script);
}

document.addEventListener('DOMContentLoaded', appendGiscusScript);

0 comments on commit a9ea151

Please sign in to comment.