summaryrefslogtreecommitdiffstats
path: root/assets/js/giscus.js
blob: 510154d7ab6934466fb51d5944ddef3f65edf9e2 (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
import {
  category,
  categoryId,
  emitMetadata,
  inputPosition,
  lang,
  mapping,
  reactionsEnabled,
  repo,
  repoId,
  strict,
  theme
} from '@params';

// The article I found interesting and might be used as a reference
// for comments theming in the future: https://www.brycewray.com/posts/2023/08/making-giscus-less-gabby/
document.addEventListener('DOMContentLoaded', function () {
  const giscusAttributes = {
    'src': 'https://giscus.app/client.js',
    'data-repo': repo,
    'data-repo-id': repoId,
    'data-category': category,
    'data-category-id': categoryId,
    'data-mapping': mapping,
    'data-strict': strict,
    'data-reactions-enabled': reactionsEnabled,
    'data-emit-metadata': emitMetadata,
    'data-input-position': inputPosition,
    'data-theme': theme,
    'data-lang': lang,
    'crossorigin': 'anonymous',
    'async': ''
  };

  // Dynamically create script tag
  const giscusScript = document.createElement('script');
  Object.entries(giscusAttributes).forEach(([key, value]) => giscusScript.setAttribute(key, value));
  document.getElementById('giscus').appendChild(giscusScript);
});