|
1 | 1 | {% 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 --> |
9 | 22 | <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"; |
15 | 29 |
|
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 | + } |
22 | 33 |
|
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"; |
25 | 42 |
|
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 | + } |
31 | 50 | }); |
32 | | - } |
| 51 | + }); |
33 | 52 | </script> |
34 | 53 | {% endif %} |
0 commit comments