|
| 1 | +<!-- https://giscus.app/ --> |
| 2 | +<script> |
| 3 | + (function () { |
| 4 | + const themeMapper = Theme.getThemeMapper('light', 'dark_dimmed'); |
| 5 | + const initTheme = themeMapper[Theme.visualState]; |
| 6 | + |
| 7 | + let lang = '{{ site.comments.giscus.lang | default: lang }}'; |
| 8 | + {%- comment -%} https://github.com/giscus/giscus/tree/main/locales {%- endcomment -%} |
| 9 | + if (lang.length > 2 && !lang.startsWith('zh')) { |
| 10 | + lang = lang.slice(0, 2); |
| 11 | + } |
| 12 | + |
| 13 | + let giscusAttributes = { |
| 14 | + src: 'https://giscus.app/client.js', |
| 15 | + 'data-repo': '{{ site.comments.giscus.repo}}', |
| 16 | + 'data-repo-id': '{{ site.comments.giscus.repo_id }}', |
| 17 | + 'data-category': '{{ site.comments.giscus.category }}', |
| 18 | + 'data-category-id': '{{ site.comments.giscus.category_id }}', |
| 19 | + 'data-mapping': '{{ site.comments.giscus.mapping | default: 'pathname' }}', |
| 20 | + 'data-strict' : '{{ site.comments.giscus.strict | default: '0' }}', |
| 21 | + 'data-reactions-enabled': '{{ site.comments.giscus.reactions_enabled | default: '1' }}', |
| 22 | + 'data-emit-metadata': '0', |
| 23 | + 'data-theme': initTheme, |
| 24 | + 'data-input-position': '{{ site.comments.giscus.input_position | default: 'bottom' }}', |
| 25 | + 'data-lang': lang, |
| 26 | + 'data-loading': 'lazy', |
| 27 | + crossorigin: 'anonymous', |
| 28 | + async: '' |
| 29 | + }; |
| 30 | + |
| 31 | + let giscusNode = document.createElement('script'); |
| 32 | + Object.entries(giscusAttributes).forEach(([key, value]) => |
| 33 | + giscusNode.setAttribute(key, value) |
| 34 | + ); |
| 35 | + |
| 36 | + const $footer = document.querySelector('footer'); |
| 37 | + $footer.insertAdjacentElement("beforebegin", giscusNode); |
| 38 | + |
| 39 | + addEventListener('message', (event) => { |
| 40 | + if (event.source === window && event.data && event.data.id === Theme.ID) { |
| 41 | + const newTheme = themeMapper[Theme.visualState]; |
| 42 | + |
| 43 | + const message = { |
| 44 | + setConfig: { |
| 45 | + theme: newTheme |
| 46 | + } |
| 47 | + }; |
| 48 | + |
| 49 | + const giscus = |
| 50 | + document.getElementsByClassName('giscus-frame')[0].contentWindow; |
| 51 | + giscus.postMessage({ giscus: message }, 'https://giscus.app'); |
| 52 | + } |
| 53 | + }); |
| 54 | + })(); |
| 55 | +</script> |
0 commit comments