summaryrefslogtreecommitdiff
path: root/layouts/_partials/posts/comment.html
blob: 6e178e5ed6e6f4403ed171532b85150d5656c686 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
{{ with .Params.comments }}
<!-- Static Comments -->
<div class="my-8">
    <p class="text-secondary">{{ T "postPage.staticCommentsSectionHeader" }}</p>
    {{ range . }}
        <div class="text-xl border-b border-solid border-[#ccc] py-4 px-1">
            <div class="mb-4 flex justify-between">
                <span class="font-bold">{{ .name }}</span>
                <span class="text-secondary">{{ .date }}</span>
            </div>
            <div>
                {{ .content | safeHTML }}
            </div>
            <div class="text-4 text-right text-secondary">
                {{ with .source }}
                <p class="font-mono">{{ T "postPage.originallyPostedOn" . }}</p>
                {{ end }}
            </div>
        </div>
    {{ end }}
</div>
{{ end }}

<!-- email info -->
<p class="text-size-sm text-secondary">
    *{{ T "emailMe" }} <a href="mailto:{{ .Site.Params.email }}">{{ .Site.Params.email }}</a>
</p>

<!-- giscus container -->
<div class="giscus">
    <p style="text-align:center">
        {{ T "postPage.commentNotLoaded" }}
    </p>
</div>

<!-- giscus script -->
<script>
function loadGiscus() {
    if (document.querySelector('iframe.giscus-frame')) return; // 防止重复加载

    const script = document.createElement("script");
    script.src = "https://giscus.app/client.js";
    script.setAttribute("data-repo", "{{ .Site.Params.giscus.repo }}");
    script.setAttribute("data-repo-id", "{{ .Site.Params.giscus.repoId }}");
    script.setAttribute("data-category", "{{ .Site.Params.giscus.category }}");
    script.setAttribute("data-category-id", "{{ .Site.Params.giscus.categoryId }}");
    script.setAttribute("data-mapping", "{{ .Site.Params.giscus.mapping }}");
    script.setAttribute("data-strict", "{{ .Site.Params.giscus.strict }}");
    script.setAttribute("data-reactions-enabled", "{{ .Site.Params.giscus.reactionsEnabled }}");
    script.setAttribute("data-emit-metadata", "1");
    script.setAttribute("data-input-position", "{{ .Site.Params.giscus.inputPosition }}");
    script.setAttribute("data-theme", "{{ .Site.Params.giscus.theme }}");
    script.setAttribute("data-lang", "{{ T "lang" }}");
    script.setAttribute("crossorigin", "anonymous");
    script.async = true;
    document.body.appendChild(script);
}

const observer = new IntersectionObserver((entries, obs) => {
    if (entries[0].isIntersecting) {
    loadGiscus();
    obs.disconnect();
    }
});

observer.observe(document.getElementById("action-menu"));
</script>