diff --git a/DISCOVER/_static/js/logo-switcher.js b/DISCOVER/_static/js/logo-switcher.js index 007526ca5..1af2f3685 100644 --- a/DISCOVER/_static/js/logo-switcher.js +++ b/DISCOVER/_static/js/logo-switcher.js @@ -1,25 +1,51 @@ document.addEventListener('DOMContentLoaded', () => { const logos = document.querySelectorAll('.logo__image'); const isTagsFolder = window.location.pathname.includes('/_tags/'); + logos.forEach(logo => { if (logo.classList.contains('only-light')) { - logo.src = isTagsFolder ? '../_static/images/logo-light.png' : '_static/images/logo-light.png';// Replacing with the light logo + logo.src = isTagsFolder + ? '../_static/images/logo-light.png' + : '_static/images/logo-light.png'; } else if (logo.classList.contains('only-dark')) { - logo.src = isTagsFolder ? '../_static/images/logo-dark.png' : '_static/images/logo-dark.png';// Replacing with the dark logo + logo.src = isTagsFolder + ? '../_static/images/logo-dark.png' + : '_static/images/logo-dark.png'; } }); 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 + let mainLogo = document.querySelector( + ".bd-content img:not(.only-dark,.dark-light)" + ); + let isDarkMode = + document.documentElement.getAttribute("data-theme") === "dark"; if (mainLogo) { - mainLogo.src = isDarkMode ? "_static/images/logo-dark.png" : "_static/images/logo-light.png"; // Change image source + mainLogo.src = isDarkMode + ? "_static/images/logo-dark.png" + : "_static/images/logo-light.png"; + } + + // ✅ ADD TOOLTIP + ARIA-LABEL FOR THEME SWITCHER + const themeSwitcher = document.querySelector(".dark-light"); + if (themeSwitcher) { + if (isDarkMode) { + themeSwitcher.setAttribute("title", "Switch to light mode"); + themeSwitcher.setAttribute("aria-label", "Switch to light mode"); + } else { + themeSwitcher.setAttribute("title", "Switch to dark mode"); + themeSwitcher.setAttribute("aria-label", "Switch to dark mode"); + } } } - // Listen for attribute changes on that is the root node of the document + // Listen for attribute changes on const observer = new MutationObserver(updateLogo); - observer.observe(document.documentElement, { attributes: true, attributeFilter: ["data-theme"] }); + observer.observe(document.documentElement, { + attributes: true, + attributeFilter: ["data-theme"], + }); + updateLogo(); -}); \ No newline at end of file +}); diff --git a/DISCOVER/_templates/footer.html b/DISCOVER/_templates/footer.html new file mode 100644 index 000000000..065c30bdc --- /dev/null +++ b/DISCOVER/_templates/footer.html @@ -0,0 +1,15 @@ +{% extends "!footer.html" %} + +{% block footer %} + {{ super() }} + +
+ + NumFOCUS + +
+{% endblock %} diff --git a/DISCOVER/conf.py b/DISCOVER/conf.py index b7592bc1f..9f738d930 100644 --- a/DISCOVER/conf.py +++ b/DISCOVER/conf.py @@ -1,112 +1,191 @@ import json import os -# Get version and language from environment variables +# ------------------------------------------------- +# Basic project info +# ------------------------------------------------- + version = os.environ.get("WEBSITE_VERSION", "dev") release = version language = os.environ.get("WEBSITE_LANGUAGE", "en") -baseurl = 'https://discover-cookbook.numfocus.org' +author = "Community" +copyright = "2023" + +baseurl = "https://discover-cookbook.numfocus.org" +html_baseurl = baseurl + +# ------------------------------------------------- +# Paths & exclusions +# ------------------------------------------------- + +exclude_patterns = [ + "**.ipynb_checkpoints", + ".DS_Store", + "Thumbs.db", + "_build", +] + +locale_dirs = ["../locales"] +gettext_uuid = True +gettext_compact = False + +# ------------------------------------------------- +# Language switcher context +# ------------------------------------------------- + +language_json_path = os.path.join( + os.path.dirname(__file__), "_static", "languages.json" +) -# Load language data from languages.json -language_json_path = os.path.join(os.path.dirname(__file__), '_static', 'languages.json') language_data = [] -current_language_name = None +current_language_name = language + if os.path.exists(language_json_path): - with open(language_json_path, 'r', encoding='utf-8') as f: + with open(language_json_path, "r", encoding="utf-8") as f: all_languages = json.load(f) -# Get the current language name -current_language_name = next((lang['name_local'] for lang in all_languages if lang['code'] == language), language) + current_language_name = next( + (lang["name_local"] for lang in all_languages if lang["code"] == language), + language, + ) -# Filter out hidden languages for the dropdown -language_data = [lang for lang in all_languages if not lang.get('hidden', False)] + language_data = [ + lang for lang in all_languages if not lang.get("hidden", False) + ] html_context = { "languages": language_data, "current_language_name": current_language_name, "current_language": language, "current_version": version, - "baseurl": baseurl + "baseurl": baseurl, } -html_baseurl = baseurl - -author = 'Community' -comments_config = {'hypothesis': False, 'utterances': False} -copyright = '2023' -exclude_patterns = ['**.ipynb_checkpoints', '.DS_Store', 'Thumbs.db', '_build'] -# configure translations -locale_dirs = ["../locales"] -# recommendations from https://docs.readthedocs.com/platform/stable/guides/manage-translations-sphinx.html#create-translatable-files -gettext_uuid = True -gettext_compact = False +# ------------------------------------------------- +# Extensions +# ------------------------------------------------- extensions = [ - 'sphinx_togglebutton', - 'sphinx_copybutton', - 'myst_parser', - 'jupyter_book', - 'sphinx_external_toc', - 'sphinx.ext.intersphinx', - 'sphinx_design', - 'sphinx_book_theme', - 'sphinx_tags', - 'sphinx_jupyterbook_latex', - 'sphinx_multitoc_numbering' + "sphinx_togglebutton", + "sphinx_copybutton", + "myst_parser", + "jupyter_book", + "sphinx_external_toc", + "sphinx.ext.intersphinx", + "sphinx_design", + "sphinx_book_theme", + "sphinx_tags", + "sphinx_jupyterbook_latex", + "sphinx_multitoc_numbering", ] + +# ------------------------------------------------- +# External TOC +# ------------------------------------------------- + +external_toc_path = "_toc.yml" external_toc_exclude_missing = False -external_toc_path = '_toc.yml' -html_baseurl = '' -html_css_files = ['css/mainLogo.css','css/Switchers.css'] -html_favicon = '' -html_js_files = ['js/footer.js', 'js/logo-switcher.js'] -html_logo = '_static/images/logo-light.png' -html_sourcelink_suffix = '' -html_static_path = ['_static'] -html_theme = 'sphinx_book_theme' + +# ------------------------------------------------- +# Static files +# ------------------------------------------------- + +html_static_path = ["_static"] + +html_css_files = [ + "css/mainLogo.css", + "css/Switchers.css", +] + +html_js_files = [ + "js/footer.js", + "js/logo-switcher.js", +] + +html_logo = "_static/images/logo-light.png" +html_favicon = "" + +# ------------------------------------------------- +# Templates +# ------------------------------------------------- + templates_path = ["_templates"] + +# ------------------------------------------------- +# Theme +# ------------------------------------------------- + +html_theme = "sphinx_book_theme" + html_theme_options = { - 'search_bar_text': 'Search this book...', - 'launch_buttons': {'notebook_interface': 'classic', 'binderhub_url': '', 'jupyterhub_url': '', 'thebe': False, 'colab_url': '', 'deepnote_url': ''}, - 'path_to_docs': 'DISCOVER', - 'repository_url': 'https://github.com/numfocus/DISCOVER-Cookbook/', - 'repository_branch': 'main', - 'extra_footer': '', - 'home_page_in_toc': True, - 'announcement': '', - 'analytics': {'google_analytics_id': '', 'plausible_analytics_domain': '', 'plausible_analytics_url': 'https://plausible.io/js/script.js'}, - 'use_repository_button': True, - 'use_edit_page_button': False, - 'use_issues_button': True, - + "search_bar_text": "Search this book...", + "path_to_docs": "DISCOVER", + "repository_url": "https://github.com/numfocus/DISCOVER-Cookbook/", + "repository_branch": "main", + "use_repository_button": True, + "use_edit_page_button": False, + "use_issues_button": True, + # Header layout - "article_header_start": ["toggle-primary-sidebar","version-switcher","language-switcher"], + "article_header_start": [ + "toggle-primary-sidebar", + "version-switcher", + "language-switcher", + ], + "navigation_with_keys": False, "show_version_warning_banner": True, - # Version switcher config + # Version switcher "switcher": { - "json_url": "https://discover-cookbook.numfocus.org/versions.json", + "json_url": "https://discover-cookbook.numfocus.org/versions.json", "version_match": version, }, + + # IMPORTANT: + # Footer MUST be empty here + # It is handled in _templates/footer.html + "extra_footer": "", } -html_title = 'DISCOVER' -latex_engine = 'pdflatex' -myst_enable_extensions = ['colon_fence', 'dollarmath', 'linkify', 'substitution', 'tasklist'] -myst_url_schemes = ['mailto', 'http', 'https'] +# ------------------------------------------------- +# Page options +# ------------------------------------------------- + +html_title = "DISCOVER" +html_sourcelink_suffix = "" + +# ------------------------------------------------- +# MyST & notebooks +# ------------------------------------------------- + +myst_enable_extensions = [ + "colon_fence", + "dollarmath", + "linkify", + "substitution", + "tasklist", +] + +myst_url_schemes = ["mailto", "http", "https"] + nb_execution_allow_errors = False -nb_execution_cache_path = '' -nb_execution_excludepatterns = [] -nb_execution_in_temp = False -nb_execution_mode = 'force' +nb_execution_mode = "force" nb_execution_timeout = 30 -nb_output_stderr = 'show' +nb_output_stderr = "show" + +# ------------------------------------------------- +# Numbering & tags +# ------------------------------------------------- + numfig = True -pygments_style = 'sphinx' -suppress_warnings = ['etoc.toctree'] +pygments_style = "sphinx" +suppress_warnings = ["etoc.toctree"] + tags_create_tags = True -tags_extension = ['md'] +tags_extension = ["md"] + use_jupyterbook_latex = True use_multitoc_numbering = True +latex_engine = "pdflatex"