Skip to content

Commit 240ac9a

Browse files
committed
moving comment from disqus back to giscus
1 parent 35f637f commit 240ac9a

2 files changed

Lines changed: 46 additions & 27 deletions

File tree

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,53 @@
11
{% if page.meta.comments %}
2-
<h2 id="__comments">
3-
<span class="twemoji" style="margin-right: 10px;">
4-
{% include ".icons/octicons/comment-discussion-24.svg" %}
5-
</span>
6-
{{ lang.t("meta.comments") }}
7-
</h2>
8-
<div id="disqus_thread"></div>
2+
<h2 id="__comments">{{ lang.t("meta.comments") }}</h2>
3+
<!-- Insert generated snippet here -->
4+
<script
5+
src="https://giscus.app/client.js"
6+
data-repo="copdips/copdips.github.io"
7+
data-repo-id="MDEwOlJlcG9zaXRvcnkxMzMyNzI0OTY="
8+
data-category="Q&A"
9+
data-category-id="DIC_kwDOB_GTsM4Cbgni"
10+
data-mapping="pathname"
11+
data-strict="0"
12+
data-reactions-enabled="1"
13+
data-emit-metadata="0"
14+
data-input-position="bottom"
15+
data-theme="preferred_color_scheme"
16+
data-lang="en"
17+
crossorigin="anonymous"
18+
async
19+
></script>
20+
21+
<!-- Synchronize Giscus theme with palette -->
922
<script>
10-
var disqus_config = function () {
11-
this.page.url = "{{ page.canonical_url }}";
12-
this.page.identifier =
13-
"{{ page.canonical_url | replace(config.site_url, '') }}"; // (1)!
14-
};
23+
var giscus = document.querySelector("script[src*=giscus]");
24+
25+
// Set palette on initial load
26+
var palette = __md_get("__palette");
27+
if (palette && typeof palette.color === "object") {
28+
var theme = palette.color.scheme === "slate" ? "transparent_dark" : "light";
1529

16-
/* Set up for the first time */
17-
if (typeof DISQUS === "undefined") {
18-
var script = document.createElement("script");
19-
script.async = true;
20-
script.src = "https://{{ config.extra.disqus }}.disqus.com/embed.js";
21-
script.setAttribute("data-timestamp", Date.now());
30+
// Instruct Giscus to set theme
31+
giscus.setAttribute("data-theme", theme);
32+
}
2233

23-
/* Inject script tag */
24-
document.body.appendChild(script);
34+
// Register event handlers after documented loaded
35+
document.addEventListener("DOMContentLoaded", function () {
36+
var ref = document.querySelector("[data-md-component=palette]");
37+
ref.addEventListener("change", function () {
38+
var palette = __md_get("__palette");
39+
if (palette && typeof palette.color === "object") {
40+
var theme =
41+
palette.color.scheme === "slate" ? "transparent_dark" : "light";
2542

26-
/* Set up on navigation (instant loading) */
27-
} else {
28-
DISQUS.reset({
29-
reload: true,
30-
config: disqus_config,
43+
// Instruct Giscus to change theme
44+
var frame = document.querySelector(".giscus-frame");
45+
frame.contentWindow.postMessage(
46+
{ giscus: { setConfig: { theme } } },
47+
"https://giscus.app"
48+
);
49+
}
3150
});
32-
}
51+
});
3352
</script>
3453
{% endif %}

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extra:
1919
# 1. https://github.com/squidfunk/mkdocs-material/discussions/2138#discussioncomment-250454
2020
# 2. https://github.com/squidfunk/mkdocs-material/pull/3329#issuecomment-1013855846
2121
# 3. https://github.com/squidfunk/mkdocs-material/commit/f9e94184620806ceff55b6a8c2df0292b39369e4
22-
disqus: copdips
22+
# disqus: copdips
2323
analytics:
2424
provider: google
2525
property: UA-118578681-1

0 commit comments

Comments
 (0)