aboutsummaryrefslogtreecommitdiff
path: root/themes/hugo-theme-stack/layouts/partials/comments/provider/giscus.html
blob: 97fbb7734eb56f39e9b4390d426da9f85ac4457e (plain) (blame)
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
52
{{- 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 (default `en` $.Language.LanguageCode) .lang -}}"
    data-loading="{{- .loading -}}"
    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 -}}