summaryrefslogtreecommitdiff
path: root/layouts/partials/scripts.html
blob: 95010adaeeb6d3a4d1bc2672327446ef7228d746 (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
68
69
<!-- third-party libraries -->
{{ range .Site.Params.externalJSFiles -}}
<script src="{{ $.Site.Params.staticPrefix }}{{ . | relURL }}"></script>
{{- end }}
<script type="module">
/* === lazyload === */
var lazyLoadInstance = new LazyLoad();
lazyLoadInstance.update();

/* === Fancybox === */
Fancybox.bind("[data-fancybox]");

/* === tocbot === */
function loadToc() {
  tocbot.init({
    tocSelector: '#toc',
    contentSelector: '#post-content',
    headingSelector: 'h2, h3:not(blockquote > h3)',
    hasInnerContainers: true,
    scrollSmoothOffset: -30
  });
}
loadToc();

/* === littlefoot === */
littlefoot.littlefoot(littlefootOptions)

/* === giscus === */
function loadGiscus() {
  const giscusContainer = document.querySelector('.giscus'); // Make sure this matches your Giscus container class
  if (giscusContainer) {
      // Remove old Giscus iframe
      giscusContainer.innerHTML = '';

      // Create and append a new script
      const script = document.createElement('script');
      script.src = 'https://giscus.app/client.js';
      script.setAttribute('data-repo', 'your/repo');
      script.setAttribute('data-repo-id', 'your-repo-id');
      script.setAttribute('data-category', 'General');
      script.setAttribute('data-category-id', 'your-category-id');
      script.setAttribute('data-mapping', 'pathname');
      script.setAttribute('data-strict', '0');
      script.setAttribute('data-reactions-enabled', '1');
      script.setAttribute('data-emit-metadata', '0');
      script.setAttribute('data-input-position', 'bottom');
      script.setAttribute('data-theme', 'light');
      script.setAttribute('data-lang', '{{ T "lang" }}');
      script.crossOrigin = 'anonymous';
      script.async = true;

      giscusContainer.appendChild(script);
  }
}

/* === swup === */
const swup = new Swup({
  linkSelector: 'a[href]:not(.no-swup)'
});
swup.hooks.on('page:view', () => {
  lazyLoadInstance.update();
  Fancybox.bind("[data-fancybox]");
  loadToc();
  littlefoot.littlefoot(littlefootOptions);
  initCalHeatmap();
  initPagefind();
  loadGiscus();
});
</script>