Skip to content

Commit

Permalink
Improve Text Visibility in DISC Logo Design #149 (#159)
Browse files Browse the repository at this point in the history
* Designed the dark logo

* Designed the light logo

* Specified logo-switcher JS file

* Specified the logo-switcher script to be added in the html head

* Override webpack css (pydata_sphinx_theme)

* Create updateLogo func and a MutationObserver to update the mainLogo src

* Specified mainLogo css file
  • Loading branch information
riteshdavv authored Jan 26, 2025
1 parent 1921c79 commit cfe80d7
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
6 changes: 5 additions & 1 deletion DISCOVER/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

title: DISCOVER
author: Community
logo: logo.png
logo: _static/logo-light.png

# Force re-execution of notebooks on each build.
# See https://jupyterbook.org/content/execute.html
Expand All @@ -21,6 +21,10 @@ repository:
html:
use_issues_button: true
use_repository_button: true
html_in_header:
- '<script src="_static/logo-switcher.js"></script>'
extra_css:
- _static/mainLogo.css

# config sphinx tags extension
sphinx:
Expand Down
Binary file added DISCOVER/_static/logo-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DISCOVER/_static/logo-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions DISCOVER/_static/logo-switcher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
document.addEventListener('DOMContentLoaded', () => {
const logos = document.querySelectorAll('.logo__image');

logos.forEach(logo => {
if (logo.classList.contains('only-light')) {
logo.src = '_static/logo-light.png'; // Replacing with the light logo
} else if (logo.classList.contains('only-dark')) {
logo.src = '_static/logo-dark.png'; // Replacing with the dark logo
}
});

function updateLogo() {
let mainLogo = document.querySelector(".bd-content img:not(.only-dark,.dark-light)"); // Select the image
let isDarkMode = document.documentElement.getAttribute("data-theme") === "dark"; // Check theme

if (mainLogo) {
mainLogo.src = isDarkMode ? "_static/logo-dark.png" : "_static/logo-light.png"; // Change image source
}
}

// Listen for attribute changes on <html> that is the root node of the document
const observer = new MutationObserver(updateLogo);
observer.observe(document.documentElement, { attributes: true, attributeFilter: ["data-theme"] });
updateLogo();
});
7 changes: 7 additions & 0 deletions DISCOVER/_static/mainLogo.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
html[data-theme=dark] .bd-content img:not(.only-dark,.dark-light) {
background: transparent !important;
border-radius: .25rem;
}
html .bd-content img:not(.only-dark,.dark-light){
padding: 1rem 0;
}

0 comments on commit cfe80d7

Please sign in to comment.