Skip to content

Commit c44f920

Browse files
authored
feat: add comment system (doocs#2249)
1 parent 4ee8b37 commit c44f920

File tree

7 files changed

+72
-0
lines changed

7 files changed

+72
-0
lines changed

docs-en/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
comments: true
3+
---
4+
15
<p align="center">
26
<a href="https://github.com/doocs/leetcode"><img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/images/leetcode-doocs.png" alt="LeetCode-GitHub-Doocs"></a>
37
</p>

docs-en/intro/contribution.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
comments: true
3+
---
4+
15
## Our Top Contributors
26

37
This project exists thanks to all the people who contribute.

docs/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
comments: true
3+
---
4+
15
<p align="center">
26
<a href="https://github.com/doocs/leetcode"><img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/images/leetcode-doocs.png" alt="LeetCode-GitHub-Doocs"></a>
37
</p>

docs/intro/contribution.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
comments: true
3+
---
4+
15
## 贡献者
26

37
感谢以下所有朋友对本项目的贡献!

main.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,13 @@ def get_paths(dirs: str, m: int):
165165
if not os.path.exists(docs_dir):
166166
os.makedirs(docs_dir)
167167
new_path = os.path.join(docs_dir, f"{num}.md")
168+
# 开启评论
169+
"""
170+
---
171+
comments: true
172+
---
173+
"""
174+
content = '---\ncomments: true\n---\n\n' + content
168175
with open(new_path, "w", encoding="utf-8") as f:
169176
f.write(content)
170177

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ copyright: Copyright &copy; 2024 Doocs
1010

1111
theme:
1212
name: material
13+
custom_dir: overrides
1314
features:
1415
- announce.dismiss
1516
- content.code.annotate

overrides/partials/comments.html

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{% if page.meta.comments %}
2+
<h2 id="__comments">{{ lang.t("meta.comments") }}</h2>
3+
<script src="https://giscus.app/client.js"
4+
data-repo="doocs/leetcode"
5+
data-repo-id="MDEwOlJlcG9zaXRvcnkxNDkwMDEzNjU="
6+
data-category="Announcements"
7+
data-category-id="DIC_kwDOCOGUlc4CZmhe"
8+
data-mapping="pathname"
9+
data-strict="0"
10+
data-reactions-enabled="1"
11+
data-emit-metadata="0"
12+
data-input-position="top"
13+
data-theme="preferred_color_scheme"
14+
data-lang="zh-CN"
15+
crossorigin="anonymous"
16+
async>
17+
</script>
18+
19+
<!-- Synchronize giscus theme with palette -->
20+
<script>
21+
var giscus = document.querySelector("script[src*=giscus]")
22+
23+
/* Set palette on initial load */
24+
var palette = __md_get("__palette")
25+
if (palette && typeof palette.color === "object") {
26+
var theme = palette.color.scheme === "slate" ? "dark" : "light"
27+
giscus.setAttribute("data-theme", theme) // (1)!
28+
}
29+
30+
/* Register event handlers after documented loaded */
31+
document.addEventListener("DOMContentLoaded", function() {
32+
var ref = document.querySelector("[data-md-component=palette]")
33+
ref.addEventListener("change", function() {
34+
var palette = __md_get("__palette")
35+
if (palette && typeof palette.color === "object") {
36+
var theme = palette.color.scheme === "slate" ? "dark" : "light"
37+
38+
/* Instruct giscus to change theme */
39+
var frame = document.querySelector(".giscus-frame")
40+
frame.contentWindow.postMessage(
41+
{ giscus: { setConfig: { theme } } },
42+
"https://giscus.app"
43+
)
44+
}
45+
})
46+
})
47+
</script>
48+
{% endif %}

0 commit comments

Comments
 (0)