File tree Expand file tree Collapse file tree 1 file changed +18
-7
lines changed
src/resources/formats/html/giscus Expand file tree Collapse file tree 1 file changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -30,16 +30,25 @@ function loadGiscusWhenReady() {
3030 document .getElementById (" quarto-content" ).appendChild (script);
3131 };
3232
33+ let observer;
34+ const loadIfBodyReady = () => {
35+ // Check if the body has the 'quarto-light' or 'quarto-dark' class
36+ if (! (document .body .classList .contains (' quarto-light' ) || document .body .classList .contains (' quarto-dark' ))) {
37+ return false ;
38+ }
39+ loadGiscus ();
40+ observer .disconnect ();
41+ return true ;
42+ };
43+
3344 // MutationObserver to detect when the 'quarto-light' or 'quarto-dark' class is added to the body
34- const observer = new MutationObserver ((mutations ) => {
45+ observer = new MutationObserver ((mutations ) => {
3546 for (const mutation of mutations) {
36- if (mutation .type === " attributes" && mutation .attributeName === " class" ) {
37- if (document .body .classList .contains (' quarto-light' ) || document .body .classList .contains (' quarto-dark' )) {
38- loadGiscus ();
39- observer .disconnect (); // Stop observing once Giscus is loaded
40- break ;
47+ if (mutation .type === " attributes" &&
48+ mutation .attributeName === " class" &&
49+ loadIfBodyReady ()) {
50+ break ; // Stop observing if Giscus is loaded
4151 }
42- }
4352 }
4453 });
4554
@@ -48,6 +57,8 @@ function loadGiscusWhenReady() {
4857 attributes: true ,
4958 attributeFilter: [" class" ],
5059 });
60+
61+ loadIfBodyReady (); // Initial check in case the class is already present
5162}
5263loadGiscusWhenReady ();
5364 </script >
You can’t perform that action at this time.
0 commit comments