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

utterances.html « third-party « partials « layouts - github.com/reuixiy/hugo-theme-meme.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 26d7cf15e1748f6a4805491774f2357ea49f349e (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
{{- $src := partial "utils/lib.html" (dict "$" . "type" "utterances") -}}

<script>
    function loadComments() {
        (function() {
            const utterances = document.getElementById("utterances");
            if (!utterances) {
                return;
            }
            const script = document.createElement('script');
            script.src = '{{ $src }}';
            script.async = true;
            script.crossOrigin = 'anonymous';
            script.setAttribute('repo', '{{ .Site.Params.utterancesRepo }}');
            script.setAttribute('issue-term', '{{ .Site.Params.utterancesIssueTerm }}');
            {{ template "utterances-theme" . }}
            {{ with .Site.Params.utterancesLabel }}
                script.setAttribute('label', '{{ . }}');
            {{ end }}
            utterances.appendChild(script);
        })();
    }
</script>

{{- define "utterances-theme" -}}
    {{- $theme := .Site.Params.utterancesTheme | default "github-light" -}}
    {{- if and .Site.Params.enableDarkMode (eq .Site.Params.defaultTheme "dark") -}}
        {{- $theme = .Site.Params.utterancesThemeDark | default "photon-dark" -}}
    {{- end -}}

    {{- if .Site.Params.enableDarkMode -}}
        const isDark = getCurrentTheme() === 'dark';
        if (isDark) {
            script.setAttribute('theme', '{{ .Site.Params.utterancesThemeDark | default "photon-dark" }}');
        } else {
            script.setAttribute('theme', '{{ .Site.Params.utterancesTheme | default "github-light" }}');
        }
    {{- else -}}
        script.setAttribute('theme', '{{ $theme }}');
    {{- end -}}
{{- end -}}