Welcome to mirror list, hosted at ThFree Co, Russian Federation.

giscus.html « provider « comments « partials « layouts - github.com/CaiJimmy/hugo-theme-stack.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f7f435dfd76ac889f24cc856e7b2bdb3fa8b4f4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{{- with .Site.Params.comments.giscus -}}
<script
    src="https://giscus.app/client.js"
    data-repo="{{- .repo -}}"
    data-repo-id="{{- .repoID -}}"
    data-category="{{- .category -}}"
    data-category-id="{{- .categoryID -}}"
    data-mapping="{{- default `title` .mapping -}}"
    data-strict="{{- default 0 .strict -}}"
    data-reactions-enabled="{{- default 1 .reactionsEnabled -}}"
    data-emit-metadata="{{- default 0 .emitMetadata -}}"
    data-input-position="{{- default `top` .inputPosition -}}"
    data-theme="{{- default `light` .lightTheme -}}"
    data-lang="{{- default `en` .lang -}}"
    crossorigin="anonymous"
    async
></script>
<script>
    function setGiscusTheme(theme) {
        let giscus = document.querySelector("iframe.giscus-frame");
        if (giscus) {
            giscus.contentWindow.postMessage(
                {
                    giscus: {
                        setConfig: {
                            theme: theme,
                        },
                    },
                },
                "https://giscus.app"
            );
        }
    }

    (function () {
        addEventListener("message", (e) => {
            if (event.origin !== "https://giscus.app") return;
            handler();
        });
        window.addEventListener("onColorSchemeChange", handler);

        function handler() {
            if (document.documentElement.dataset.scheme === "light") {
                setGiscusTheme('{{- default "light" .lightTheme -}}');
            } else {
                setGiscusTheme('{{- default "dark_dimmed" .darkTheme -}}');
            }
        }
    })();
</script>
{{- end -}}