Skip to content

Commit

Permalink
fix: fix giscus theme issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Mar 25, 2024
1 parent 5a26a0d commit f700893
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
27 changes: 27 additions & 0 deletions themes/default/js/giscus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
;(() => {
const targetElement = document.documentElement;
const defaultTheme = targetElement.getAttribute("data-color-mode").toLocaleLowerCase();
changeGiscusTheme(defaultTheme)
const observer = new MutationObserver((mutationsList, observer) => {
for(const mutation of mutationsList) {
if (mutation.type === 'attributes') {
const value = targetElement.getAttribute("data-color-mode").toLocaleLowerCase();
changeGiscusTheme(value)
}
}
});

observer.observe(targetElement, {
attributes: true,
attributeOldValue: true
});

function changeGiscusTheme(theme) {
const iframe = document.querySelector('.giscus-frame');
if (iframe) {
iframe.contentWindow.postMessage({
giscus: { theme }
}, 'https://giscus.app');
}
}
})();
3 changes: 3 additions & 0 deletions themes/default/markdown.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
<markdown-style theme-auto-switch-disabled>
<%- html %>
<%- giscusScript %>
<% if (giscusScript) { %>
<script src="<%= RELATIVE_PATH %>js/giscus.js?v=<%=idocVersion%>"></script>
<% } %>
<%- include('partial/article-footer'); %>
</markdown-style>
<%- include('partial/tocs'); %>
Expand Down

0 comments on commit f700893

Please sign in to comment.