aboutsummaryrefslogtreecommitdiff
path: root/themes/hugo-theme-stack/layouts/partials/comments/provider/beaudar.html
blob: 761801fa07f3bd6977adf453ef6025d76fb598b0 (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
<script
  src="https://beaudar.lipk.org/client.js"
  repo="{{ .Site.Params.comments.beaudar.repo }}"
  issue-term="{{ .Site.Params.comments.beaudar.issueTerm }}"
  {{ with .Site.Params.comments.beaudar.label }}
  label="{{ . }}"
  {{ end }}
  theme="{{ .Site.Params.comments.beaudar.theme }}"
  crossorigin="anonymous"
  async
></script>

<style>
  .beaudar {
    max-width: unset;
  }
</style>

<script>
  let beaudarLoaded = false;

  function setBeaudarTheme(theme) {
    let beaudar = document.querySelector(".beaudar iframe");
    if (beaudar) {
      beaudar.contentWindow.postMessage(
        {
          type: "set-theme",
          theme: `github-${theme}`,
        },
        "https://beaudar.lipk.org"
      );
    }
  }

  addEventListener("message", (event) => {
    if (event.origin !== "https://beaudar.lipk.org") return;
    /// Called when Beaudar is ready
    beaudarLoaded = true;
    setBeaudarTheme(document.documentElement.dataset.scheme);
  });

  window.addEventListener("onColorSchemeChange", (e) => {
    if (!beaudarLoaded) return;
    setBeaudarTheme(e.detail);
  });
</script>