|
| 1 | +--- |
| 2 | +const customCss = new URL("/css/giscus-custom.css", Astro.site).href; |
| 3 | +--- |
| 4 | + |
| 5 | +<section class="comments"> |
| 6 | + <script |
| 7 | + is:inline |
| 8 | + src="https://giscus.app/client.js" |
| 9 | + data-repo="aaronryu/aaronryu.github.io" |
| 10 | + data-repo-id="MDEwOlJlcG9zaXRvcnkxNjMwOTgxOTc=" |
| 11 | + data-category="Announcements" |
| 12 | + data-category-id="DIC_kwDOCbiuVc4C8t_o" |
| 13 | + data-mapping="pathname" |
| 14 | + data-strict="0" |
| 15 | + data-reactions-enabled="1" |
| 16 | + data-emit-metadata="0" |
| 17 | + data-input-position="top" |
| 18 | + data-theme={customCss} |
| 19 | + data-lang="ko" |
| 20 | + data-loading="lazy" |
| 21 | + crossorigin="anonymous" |
| 22 | + async |
| 23 | + > |
| 24 | + </script> |
| 25 | + <!-- preferred_color_scheme --> |
| 26 | +</section> |
| 27 | + |
| 28 | +<script is:inline> |
| 29 | + function getGiscusTheme() { |
| 30 | + return document.documentElement.classList.contains("dark") ? "dark" : "light"; |
| 31 | + } |
| 32 | + |
| 33 | + function sendGiscusTheme(theme) { |
| 34 | + const iframe = document.querySelector("iframe.giscus-frame"); |
| 35 | + if (!iframe) return false; |
| 36 | + |
| 37 | + iframe.contentWindow.postMessage( |
| 38 | + { giscus: { setConfig: { theme: theme } } }, |
| 39 | + "https://giscus.app", |
| 40 | + ); |
| 41 | + return true; |
| 42 | + } |
| 43 | + |
| 44 | + // 다크 모드 토글을 감지 |
| 45 | + // + 중복 등록 방지: 이미 observer 가 있으면 스킵 |
| 46 | + if (!window.__giscusObserver) { |
| 47 | + window.__giscusObserver = new MutationObserver(() => { |
| 48 | + sendGiscusTheme(getGiscusTheme()); |
| 49 | + }); |
| 50 | + |
| 51 | + window.__giscusObserver.observe(document.documentElement, { |
| 52 | + attributes: true, |
| 53 | + attributeFilter: ["class"], |
| 54 | + }); |
| 55 | + } |
| 56 | + |
| 57 | + // Lazy Loading 방식으로 Giscus 댓글창을 로드하기에 그것이 완료되었을때 현재 테마설정을 읽어 사용하도록 |
| 58 | + window.addEventListener("message", (event) => { |
| 59 | + if (event.origin !== "https://giscus.app") return; |
| 60 | + if (!(typeof event.data === "object" && event.data.giscus)) return; |
| 61 | + |
| 62 | + // Giscus sends a message when it's finished loading |
| 63 | + sendGiscusTheme(getGiscusTheme()); |
| 64 | + }); |
| 65 | +</script> |
| 66 | + |
| 67 | +<script></script> |
0 commit comments