|
1 | 1 | {% if page.meta.comments is not defined or page.meta.comments != false %} |
2 | | -{% set twikoo = config.extra.twikoo %} |
3 | | -{% set giscus = config.extra.giscus %} |
4 | | -{% if twikoo and twikoo.env_id and not twikoo.env_id.startswith("REPLACE_WITH_") %} |
5 | | -<div id="twikoo-comments"></div> |
6 | | -<script src="https://cdn.jsdelivr.net/npm/twikoo@1.6.42/dist/twikoo.all.min.js"></script> |
7 | | -<script> |
8 | | - twikoo.init({ |
9 | | - envId: "{{ twikoo.env_id }}", |
10 | | - el: "#twikoo-comments", |
11 | | - {% if twikoo.region %} |
12 | | - region: "{{ twikoo.region }}", |
13 | | - {% endif %} |
14 | | - path: "{{ page.url | default('') }}" |
15 | | - }) |
16 | | -</script> |
17 | | -{% elif giscus and giscus.repo and giscus.repo_id and giscus.category and giscus.category_id and not giscus.category_id.startswith("REPLACE_WITH_") %} |
| 2 | +{% set utterances = config.extra.utterances %} |
| 3 | +{% if utterances and utterances.repo and utterances.issue_term %} |
18 | 4 | <script |
19 | | - src="https://giscus.app/client.js" |
20 | | - data-repo="{{ giscus.repo }}" |
21 | | - data-repo-id="{{ giscus.repo_id }}" |
22 | | - data-category="{{ giscus.category }}" |
23 | | - data-category-id="{{ giscus.category_id }}" |
24 | | - data-mapping="{{ giscus.mapping | default('pathname') }}" |
25 | | - data-strict="{{ giscus.strict | default('0') }}" |
26 | | - data-reactions-enabled="{{ giscus.reactions_enabled | default('1') }}" |
27 | | - data-emit-metadata="{{ giscus.emit_metadata | default('1') }}" |
28 | | - data-input-position="{{ giscus.input_position | default('top') }}" |
29 | | - data-theme="{{ giscus.theme | default('preferred_color_scheme') }}" |
30 | | - data-lang="{{ giscus.lang | default('en') }}" |
31 | | - data-loading="lazy" |
| 5 | + src="https://utteranc.es/client.js" |
| 6 | + repo="{{ utterances.repo }}" |
| 7 | + issue-term="{{ utterances.issue_term | default('pathname') }}" |
| 8 | + {% if utterances.label %} |
| 9 | + label="{{ utterances.label }}" |
| 10 | + {% endif %} |
| 11 | + theme="{{ utterances.theme | default('preferred-color-scheme') }}" |
32 | 12 | crossorigin="anonymous" |
33 | 13 | async> |
34 | 14 | </script> |
35 | 15 | <script> |
36 | | - var giscus = document.querySelector("script[src*=giscus]") |
| 16 | + var utterances = document.querySelector("script[src*=utteranc]") |
37 | 17 |
|
38 | | - // Set palette on initial load |
39 | | - var palette = __md_get("__palette") |
40 | | - if (giscus && palette && typeof palette.color === "object") { |
41 | | - var theme = palette.color.scheme === "slate" |
42 | | - ? "transparent_dark" |
43 | | - : "light" |
| 18 | + function getUtterancesTheme() { |
| 19 | + if (typeof __md_get !== "function") { |
| 20 | + return "{{ utterances.theme | default('preferred-color-scheme') }}" |
| 21 | + } |
44 | 22 |
|
45 | | - // Instruct Giscus to set theme |
46 | | - giscus.setAttribute("data-theme", theme) |
| 23 | + var palette = __md_get("__palette") |
| 24 | + if (palette && typeof palette.color === "object") { |
| 25 | + return palette.color.scheme === "slate" |
| 26 | + ? "{{ utterances.dark_theme | default('github-dark') }}" |
| 27 | + : "{{ utterances.light_theme | default('github-light') }}" |
| 28 | + } |
| 29 | + |
| 30 | + return "{{ utterances.theme | default('preferred-color-scheme') }}" |
| 31 | + } |
| 32 | + |
| 33 | + if (utterances) { |
| 34 | + utterances.setAttribute("theme", getUtterancesTheme()) |
47 | 35 | } |
48 | 36 |
|
49 | | - // Register event handlers after documented loaded |
50 | 37 | document.addEventListener("DOMContentLoaded", function () { |
51 | 38 | var ref = document.querySelector("[data-md-component=palette]") |
52 | 39 | if (!ref) { |
53 | 40 | return |
54 | 41 | } |
55 | 42 |
|
56 | 43 | ref.addEventListener("change", function () { |
57 | | - var palette = __md_get("__palette") |
58 | | - if (palette && typeof palette.color === "object") { |
59 | | - var theme = palette.color.scheme === "slate" |
60 | | - ? "transparent_dark" |
61 | | - : "light" |
62 | | - |
63 | | - // Instruct Giscus to change theme |
64 | | - var frame = document.querySelector(".giscus-frame") |
65 | | - if (frame && frame.contentWindow) { |
66 | | - frame.contentWindow.postMessage( |
67 | | - {giscus: {setConfig: {theme}}}, |
68 | | - "https://giscus.app" |
69 | | - ) |
70 | | - } |
| 44 | + var frame = document.querySelector(".utterances-frame") |
| 45 | + if (frame && frame.contentWindow) { |
| 46 | + frame.contentWindow.postMessage( |
| 47 | + {type: "set-theme", theme: getUtterancesTheme()}, |
| 48 | + "https://utteranc.es" |
| 49 | + ) |
71 | 50 | } |
72 | 51 | }) |
73 | 52 | }) |
74 | 53 | </script> |
75 | 54 | {% else %} |
76 | | -<!-- Comments are disabled until extra.twikoo.env_id or extra.giscus.category_id is configured. --> |
| 55 | +<!-- Comments are disabled until extra.utterances.repo and extra.utterances.issue_term are configured. --> |
77 | 56 | {% endif %} |
78 | 57 | {% endif %} |
0 commit comments