Skip to content

Commit

Permalink
Add support for giscus comments (alshedivat#1028)
Browse files Browse the repository at this point in the history
  • Loading branch information
Demi-wlw authored Mar 11, 2023
1 parent 7835f8a commit d325af7
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions assets/js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let toggleTheme = (theme) => {
let setTheme = (theme) => {
transTheme();
setHighlight(theme);
setGiscusTheme(theme);

if (theme) {
document.documentElement.setAttribute("data-theme", theme);
Expand Down Expand Up @@ -40,6 +41,21 @@ let setHighlight = (theme) => {
}
}

let setGiscusTheme = (theme) => {

function sendMessage(message) {
const iframe = document.querySelector('iframe.giscus-frame');
if (!iframe) return;
iframe.contentWindow.postMessage({ giscus: message }, 'https://giscus.app');
}

sendMessage({
setConfig: {
theme: theme
}
});

}

let transTheme = () => {
document.documentElement.classList.add("transition");
Expand Down

0 comments on commit d325af7

Please sign in to comment.