Skip to content

Commit

Permalink
(#398) Ensure Disqus works in dark mode
Browse files Browse the repository at this point in the history
Due to the Bootstrap upgrade to 5.3, Disqus
comments were not readable in dark mode. This
issue was reported and confirmed at:

https://disqus.com/home/discussion/channel-discussdisqus/embed_disqus_comments_not_changing_background_color_with_bootstrap_53_color_mode/

A change has been made to override the
color-scheme at the :root, which appears not to
affect anything else in choco-theme currently.

In addition, the Disqus JavaScript has been moved
into it's own file so that the code can be shared
across repositories.
  • Loading branch information
st3phhays committed Apr 17, 2024
1 parent df03012 commit 6301693
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 3 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"corepack",
"cssnano",
"datatables",
"Disqus",
"DOCSEARCH",
"dropoverlay",
"easymde",
Expand Down
12 changes: 12 additions & 0 deletions build/choco-theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ const init = async () => {
);
}

// Disqus
if (repository.name === repositoryConfig.community.name || repository.name === repositoryConfig.blog.name) {
parallelTasksInitial.push(
{
task: 'disqus.min.js',
source: `${repositoryConfig.theme.js}disqus.min.js`,
destination: `${repository.js}disqus.min.js`,
isFolder: false
}
);
}

// atcb-override css
if (repository.name === repositoryConfig.org.name) {
parallelTasksInitial.push(
Expand Down
1 change: 1 addition & 0 deletions dist/css/chocolatey.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Licensed under MIT (https://github.com/chocolatey/choco-theme/blob/main/LICENSE)
*/
:root {
color-scheme: unset !important;
--bs-blue-rgb: 92, 159, 216;
--bs-indigo-rgb: 102, 16, 242;
--bs-purple-rgb: 111, 66, 193;
Expand Down
2 changes: 1 addition & 1 deletion dist/css/chocolatey.min.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/css/zendesk.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Licensed under MIT (https://github.com/chocolatey/choco-theme/blob/main/LICENSE)
*/
:root {
color-scheme: unset !important;
--bs-blue-rgb: 92, 159, 216;
--bs-indigo-rgb: 102, 16, 242;
--bs-purple-rgb: 111, 66, 193;
Expand Down
2 changes: 1 addition & 1 deletion dist/css/zendesk.min.css

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions dist/js/disqus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*!
* choco-theme v0.6.2 (https://github.com/chocolatey/choco-theme#readme)
* Copyright 2020-2024 Chocolatey Software
* Licensed under MIT (https://github.com/chocolatey/choco-theme/blob/main/LICENSE)
*/
(() => {
// js/disqus.js
(() => {
const disqusShortname = "chocolatey";
const dsq = document.createElement("script");
dsq.type = "text/javascript";
dsq.async = true;
dsq.src = `//${disqusShortname}.disqus.com/embed.js`;
(document.getElementsByTagName("head")[0] || document.getElementsByTagName("body")[0]).appendChild(dsq);
document.addEventListener("themeChanged", () => {
if (document.readyState == "complete") {
DISQUS.reset({ reload: true, config: disqus_config });
}
});
})();
})();
6 changes: 6 additions & 0 deletions dist/js/disqus.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*!
* choco-theme v0.6.2 (https://github.com/chocolatey/choco-theme#readme)
* Copyright 2020-2024 Chocolatey Software
* Licensed under MIT (https://github.com/chocolatey/choco-theme/blob/main/LICENSE)
*/
(()=>{(()=>{let t="chocolatey",e=document.createElement("script");e.type="text/javascript",e.async=!0,e.src=`//${t}.disqus.com/embed.js`,(document.getElementsByTagName("head")[0]||document.getElementsByTagName("body")[0]).appendChild(e),document.addEventListener("themeChanged",()=>{document.readyState=="complete"&&DISQUS.reset({reload:!0,config:disqus_config})})})();})();
2 changes: 2 additions & 0 deletions dist/js/theme-toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
setStoredTheme(theme);
setTheme(theme);
showActiveTheme(theme, true);
const event = new Event("themeChanged");
document.dispatchEvent(event);
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion dist/js/theme-toggle.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions js/disqus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(() => {
const disqusShortname = 'chocolatey';

const dsq = document.createElement('script');
dsq.type = 'text/javascript';
dsq.async = true;
dsq.src = `//${disqusShortname}.disqus.com/embed.js`;
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);

// Disqus theme switching
// Tutorial: https://thisdevbrain.com/disqus-auto-theme-switching/
document.addEventListener('themeChanged', () => {
if (document.readyState == 'complete') {
// eslint-disable-next-line no-undef, camelcase
DISQUS.reset({ reload: true, config: disqus_config });
}
});
})();
4 changes: 4 additions & 0 deletions js/theme-toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
setStoredTheme(theme);
setTheme(theme);
showActiveTheme(theme, true);

// Create and send event for Disqus to reload
const event = new Event('themeChanged');
document.dispatchEvent(event);
});
});
});
Expand Down
1 change: 1 addition & 0 deletions scss/variables/_chocolatey-root.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
:root {
color-scheme: unset !important; // https://disqus.com/home/discussion/channel-discussdisqus/embed_disqus_comments_not_changing_background_color_with_bootstrap_53_color_mode/
@each $color, $value in $colors-rgb {
--#{$variable-prefix}#{$color}-rgb: #{$value};
}
Expand Down

0 comments on commit 6301693

Please sign in to comment.