diff --git a/_static/switcher.json b/_static/switcher.json deleted file mode 100644 index 2787f4483a55058d29270b688dba4cdd1713280b..0000000000000000000000000000000000000000 --- a/_static/switcher.json +++ /dev/null @@ -1,12 +0,0 @@ -[ - { "name": "Dev", - "version": "dev", - "url": "https://docs.beagleboard.io/latest/" - }, - { - "name": "Stable", - "version": "stable", - "url": "https://docs.beagleboard.org/latest/", - "preferred": true - } -] \ No newline at end of file diff --git a/_templates/message.html b/_templates/message.html index e5e87a324fbd5ea7a59e0f253225795a9899f932..bbfc679fe675ac92a862adc9840d5cbde98f9a72 100644 --- a/_templates/message.html +++ b/_templates/message.html @@ -1,3 +1,5 @@ +<!-- Sidebar message --> + <div class="card bg-light mt-4 text-center"> <div class="card-body"> <p class="card-text text-dark"> @@ -5,4 +7,75 @@ is all about being open, please discuss in public on our <a href="https://forum.beagleboard.org" target="_blank">forum</a>!</p> </div> -</div> \ No newline at end of file +</div> + + +<!-- Top version and announcement message --> +<script> + +// Function to check for the next div and clear it or create it if not available +function getBannerDiv() { + // Get the first element with the class 'search-button__wrapper' + const sbw = document.getElementsByClassName('search-button__wrapper'); + + // Ensure the collection is not empty to avoid errors + if (sbw.length > 0) { + const sbwElement = sbw[0]; + const nextElement = sbwElement.nextElementSibling; + + // Check if the next element exists and has the class 'pst-async-banner-revealer' + if (nextElement && nextElement.classList.contains('pst-async-banner-revealer')) { + // Clear the content of the next element + nextElement.innerHTML = ''; + } else { + // Create a new div with the required class and style if it doesn't exist + const newDiv = document.createElement('div'); + newDiv.className = 'pst-async-banner-revealer'; + newDiv.style.height = 'auto'; + sbwElement.insertAdjacentElement('afterend', newDiv); + return newDiv; // Return the newly created div + } + return nextElement; // Return the existing element + } else { + console.error("No elements with the class 'search-button__wrapper' found."); + return null; + } +} + +// Function to generate version and announcement banner HTML +function getBannerHTML() { + return ` + {% if 'docs.beagleboard.org' not in docs_url%} + <aside id="bd-header-version-warning" class="d-print-none" aria-label="Version warning"> + <div class="bd-header-announcement__content ms-auto me-auto"> + <div class="sidebar-message"> + {{ current_url }} + {% if '/docs.beagleboard.io/' in docs_url %} + {{forked_version_message}} + {% elif 'docs.beagleboard.io' in docs_url %} + {{development_version_message}} + {% else %} + {{unknown_version_message}} + {% endif %} + <a class="btn text-wrap font-weight-bold ms-3 my-1 align-baseline pst-button-link-to-stable-version" href="{{version_link}}"> + {{version_link_text}} + </a> + </div> + </div> + </aside> + {% endif %} + <aside class="bd-header-announcement" aria-label="Announcement"> + <div class="bd-header-announcement__content">{{ announcement_message }}</div> + </aside> + `; +} + +// Get the target element where the banners will be added +const bannerDiv = getBannerDiv(); + +// Add version banner and announcement banner if bannerDiv is valid +if (bannerDiv) { + bannerDiv.innerHTML = getBannerHTML(); +} + +</script> diff --git a/conf.py b/conf.py index 57eef492bdf2abe3f9a8f0495fac470a0869e13e..cc9443c62e504022592d832c3b307e479b25ae33 100644 --- a/conf.py +++ b/conf.py @@ -12,6 +12,14 @@ from pathlib import Path import pydata_sphinx_theme from sphinx.ext.imgconverter import ImagemagickConverter +# -- Banners -- +announcement_message = "Welcome to the new site for BeagleBoard.org docs!" +development_version_message = "This documentation is for a <strong> development version.</strong>" +forked_version_message = "This documentation is for a <strong> forked version.</strong>" +unknown_version_message = "This documentation is for a <strong> unknown version.</strong>" +version_link = "https://docs.beagleboard.org" +version_link_text = "Switch to released version" + # -- Project information -- project = 'BeagleBoard Docs' copyright = '2024, BeagleBoard.org Foundation' @@ -131,12 +139,8 @@ numfig = True templates_path = ['_templates'] exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'env', ".venv"] -# Version switching -docs_url = "https://docs.beagleboard.io" -json_url = "_static/switcher.json" -version_match = "dev" - # parse pages details from 'PAGES' file +docs_url = "" with open("PAGES") as f: m = re.match( ( @@ -165,14 +169,6 @@ with open("PAGES") as f: gitlab_project = "/".join((gitlab_url, gitlab_user, gitlab_repo)) docs_url = "/".join((url, slug)) -if "docs.beagleboard.org" in docs_url: - version_match = "stable" -elif "docs.beagleboard.io" in docs_url: - version_match = "dev" - -print("Version of docs is:", version_match) -print("JSON URL:", json_url) - # HTML html_theme = 'pydata_sphinx_theme' html_static_path = ["_static"] @@ -252,9 +248,7 @@ html_theme_options = { "show_toc_level": 1, "navbar_align": "right", "show_nav_level": 1, - "announcement": "Welcome to new site for BeagleBoard.org docs!", - "show_version_warning_banner": True, - "navbar_center": ["version-switcher", "navbar-nav"], + "navbar_center": ["navbar-nav"], "navbar_start": ["navbar-logo"], "navbar_end": ["theme-switcher", "navbar-icon-links"], # "navbar_persistent": ["search-button"], @@ -265,10 +259,6 @@ html_theme_options = { "secondary_sidebar_items": { "**": ["todo", "page-toc", "edit-this-page", "sourcelink","pdf", "feedback", "forum", "license-terms", "message", "oshw"] }, - "switcher": { - "json_url": json_url, - "version_match": version_match, - }, } # Variables here holds default settings @@ -300,7 +290,13 @@ html_context = { "my_vcs_site": "https://openbeagle.org/docs/docs.beagleboard.io/-/edit/main/", "oshw_details": oshw_details, "pdf_paths": pdf_paths, - "board_details": board_details + "board_details": board_details, + "announcement_message": announcement_message, + "development_version_message": development_version_message, + "forked_version_message": forked_version_message, + "unknown_version_message": unknown_version_message, + "version_link": version_link, + "version_link_text": version_link_text, } # -- Options for LaTeX output --