From af1967ea93e1de89892b9df5b7fbbbf9d6c48efc Mon Sep 17 00:00:00 2001
From: Deepak Khatri <lorforlinux@beagleboard.org>
Date: Thu, 29 Aug 2024 18:52:26 +0530
Subject: [PATCH] Add versioning and remove work in progress pill

---
 _static/switcher.json                         | 12 ++++++++
 boards/beagleconnect/freedom/index.rst        |  2 --
 boards/beagleplay/04-expansion.rst            |  2 --
 boards/beagleplay/index.rst                   |  2 --
 boards/beaglev/ahead/index.rst                |  2 --
 boards/beaglev/fire/04-expansion.rst          |  2 --
 boards/beaglev/fire/index.rst                 |  2 --
 boards/beagley/ai/03-design.rst               |  2 --
 ...-arducam-imx219-v3link-dual-camera-kit.rst |  2 --
 .../ai/demos/beagley-ai-expansion-nvme.rst    |  2 --
 .../beagley-ai-pca9685-motor-drivers.rst      |  2 --
 .../beagley-ai-using-imx219-csi-cameras.rst   |  2 --
 boards/beagley/ai/index.rst                   |  2 --
 conf.py                                       | 30 +++++++++++++++++--
 14 files changed, 39 insertions(+), 27 deletions(-)
 create mode 100644 _static/switcher.json

diff --git a/_static/switcher.json b/_static/switcher.json
new file mode 100644
index 00000000..4ebf72d8
--- /dev/null
+++ b/_static/switcher.json
@@ -0,0 +1,12 @@
+[
+    {
+        "version": "dev",
+        "url": "https://docs.beagleboard.io/latest/"
+    },
+    {
+        "name": "1.0.0 (stable)",
+        "version": "v1.0.0",
+        "url": "https://docs.beagleboard.org/latest/",
+        "preferred": true
+    }
+]
\ No newline at end of file
diff --git a/boards/beagleconnect/freedom/index.rst b/boards/beagleconnect/freedom/index.rst
index e8cfe59a..8140c518 100644
--- a/boards/beagleconnect/freedom/index.rst
+++ b/boards/beagleconnect/freedom/index.rst
@@ -3,8 +3,6 @@
 BeagleConnect Freedom
 #####################
 
-:bdg-danger:`Work in progress`
-
 BeagleConnectâ„¢ Freedom is an open-hardware wireless hardware platform developed by BeagleBoard.org and built around the TI CC1352P7 microcontroller, which supports both 
 2.4-GHz and long-range, low-power Sub-1 GHz wireless protocols. Rapidly prototyping of IoT applications is accelerated by hardware compatibility with over 1,000 mikroBUS add-on sensors,
 acutators, indicators and additional connectivity and storage options, and backed with software support utilizing the Zephyr scalable and modular real-time operating system, allowing developers
diff --git a/boards/beagleplay/04-expansion.rst b/boards/beagleplay/04-expansion.rst
index 49f6fb19..fd6c694c 100644
--- a/boards/beagleplay/04-expansion.rst
+++ b/boards/beagleplay/04-expansion.rst
@@ -3,8 +3,6 @@
 Expansion
 #########
 
-:bdg-danger:`Work in progress`
-
 .. todo::
 
    Add information on building expansion hardware for BeaglePlay.
diff --git a/boards/beagleplay/index.rst b/boards/beagleplay/index.rst
index 05fc1f8f..278e10fe 100644
--- a/boards/beagleplay/index.rst
+++ b/boards/beagleplay/index.rst
@@ -3,8 +3,6 @@
 BeaglePlay
 ##########
 
-:bdg-danger:`Work in progress`
-
 BeaglePlay is an open-source single board computer based on the Texas Instruments AM6254 quad-core Cortex-A53 Arm SoC designed to simplify the process of adding
 sensors, actuators, indicators, human interfaces, and connectivity to a reliable embedded system.
 
diff --git a/boards/beaglev/ahead/index.rst b/boards/beaglev/ahead/index.rst
index 4a98a0d6..61c59c37 100644
--- a/boards/beaglev/ahead/index.rst
+++ b/boards/beaglev/ahead/index.rst
@@ -3,8 +3,6 @@
 BeagleV-Ahead
 ###################
 
-:bdg-danger:`Work in progress`
-
 BeagleV-Ahead is a high-performance open-source RISC-V single board computer (SBC) built around the Alibaba TH1520 SoC. It has the same P8 & P9 cape header pins as
 BeagleBone Black allowing you to stack your favourite BeagleBone cape on top to expand it's capability.
 Featuring a powerful quad-core RISC-V processor BeagleV Ahead is designed as an affordable
diff --git a/boards/beaglev/fire/04-expansion.rst b/boards/beaglev/fire/04-expansion.rst
index eed3e59c..1e8c1dd5 100644
--- a/boards/beaglev/fire/04-expansion.rst
+++ b/boards/beaglev/fire/04-expansion.rst
@@ -3,8 +3,6 @@
 Expansion
 #########
 
-:bdg-danger:`Work in progress`
-
 Cape Headers
 *************
 
diff --git a/boards/beaglev/fire/index.rst b/boards/beaglev/fire/index.rst
index fc634c01..191cb002 100644
--- a/boards/beaglev/fire/index.rst
+++ b/boards/beaglev/fire/index.rst
@@ -3,8 +3,6 @@
 BeagleV-Fire
 ###################
 
-:bdg-danger:`Work in progress`
-
 BeagleV®-Fire is a revolutionary SBC powered by the Microchip's PolarFire® MPFS025T RISC-V System on Chip 
 (SoC) with FPGA fabric. BeagleV®-Fire opens up new horizons for developers, tinkerers, and the open-source community to explore the vast potential 
 of RISC-V architecture and FPGA technology. It has the same P8 & P9 cape header pins as BeagleBone Black allowing you to stack your favorite BeagleBone 
diff --git a/boards/beagley/ai/03-design.rst b/boards/beagley/ai/03-design.rst
index 1e6c7bbe..df25737a 100644
--- a/boards/beagley/ai/03-design.rst
+++ b/boards/beagley/ai/03-design.rst
@@ -3,8 +3,6 @@
 Design and Specifications
 #########################
 
-:bdg-danger:`Work in progress`
-
 .. todo:: Add details about all the schematic sections.
 
 If you want to know how BeagleY-AI is designed and the detailed specifications, then
diff --git a/boards/beagley/ai/demos/beagley-ai-arducam-imx219-v3link-dual-camera-kit.rst b/boards/beagley/ai/demos/beagley-ai-arducam-imx219-v3link-dual-camera-kit.rst
index 9af40a96..b0a7dd8e 100644
--- a/boards/beagley/ai/demos/beagley-ai-arducam-imx219-v3link-dual-camera-kit.rst
+++ b/boards/beagley/ai/demos/beagley-ai-arducam-imx219-v3link-dual-camera-kit.rst
@@ -3,8 +3,6 @@
 Using the Arducam Dual V3Link Camera Kit
 ############################################
 
-:bdg-danger:`Work in progress`
-
 .. todo:: Add further testing steps, results, and images.
 
 `The Arducam Dual V3Link Camera Kit <https://www.arducam.com/product/arducam-imx219-v3link-camera-kit-for-raspberry-pi/>`_ is an IMX219 based kit that leverages Texas Instruments' FPDLink technology to enable using two CSI cameras over a single port up to 15 meters away using twisted pair cables.
diff --git a/boards/beagley/ai/demos/beagley-ai-expansion-nvme.rst b/boards/beagley/ai/demos/beagley-ai-expansion-nvme.rst
index 5a0588a2..e0006726 100644
--- a/boards/beagley/ai/demos/beagley-ai-expansion-nvme.rst
+++ b/boards/beagley/ai/demos/beagley-ai-expansion-nvme.rst
@@ -3,8 +3,6 @@
 Booting from NVMe Drives
 ##########################
 
-:bdg-danger:`Work in progress`
-
 .. todo:: Add further testing steps, results, and images.
 
 BeagleY-AI supports a PCI-Express x1 interface which enables data rates of up to 1GB/s for high speed expansion. 
diff --git a/boards/beagley/ai/demos/beagley-ai-pca9685-motor-drivers.rst b/boards/beagley/ai/demos/beagley-ai-pca9685-motor-drivers.rst
index e3e235c6..1f91bcef 100644
--- a/boards/beagley/ai/demos/beagley-ai-pca9685-motor-drivers.rst
+++ b/boards/beagley/ai/demos/beagley-ai-pca9685-motor-drivers.rst
@@ -1,7 +1,5 @@
 .. _beagley-ai-pca9685-motor-drivers:
 
-:bdg-danger:`Work in progress`
-
 .. todo:: Add further testing steps, results, and images.
 
 Using PCA9685 Motor Drivers
diff --git a/boards/beagley/ai/demos/beagley-ai-using-imx219-csi-cameras.rst b/boards/beagley/ai/demos/beagley-ai-using-imx219-csi-cameras.rst
index 38d16cb6..62cfaa6b 100644
--- a/boards/beagley/ai/demos/beagley-ai-using-imx219-csi-cameras.rst
+++ b/boards/beagley/ai/demos/beagley-ai-using-imx219-csi-cameras.rst
@@ -3,8 +3,6 @@
 Using IMX219 CSI Cameras
 ############################
 
-:bdg-danger:`Work in progress`
-
 .. todo:: Add further testing steps, results, and images.
 
 Camera connection
diff --git a/boards/beagley/ai/index.rst b/boards/beagley/ai/index.rst
index 50eb2271..a7a74dd8 100644
--- a/boards/beagley/ai/index.rst
+++ b/boards/beagley/ai/index.rst
@@ -3,8 +3,6 @@
 BeagleY-AI
 ##########
 
-:bdg-danger:`Work in progress`
-
 BeagleY-AI is an open-source single board computer based on the Texas Instruments AM67A Arm-based vision processor.
 
 .. image:: images/beagley-ai-in-hand.*
diff --git a/conf.py b/conf.py
index 2e0f7f2a..aeb0335c 100644
--- a/conf.py
+++ b/conf.py
@@ -145,6 +145,27 @@ html_css_files = [
     'css/custom.css',
 ]
 
+# Define the json_url for our version switcher.
+json_url = "_static/switcher.json"
+
+# Define the version we use for matching in the version switcher.
+version_match = os.environ.get("READTHEDOCS_VERSION")
+release = pydata_sphinx_theme.__version__
+# If READTHEDOCS_VERSION doesn't exist, we're not on RTD
+# If it is an integer, we're in a PR build and the version isn't correct.
+# If it's "latest" → change to "dev" (that's what we want the switcher to call it)
+if not version_match or version_match.isdigit() or version_match == "latest":
+    # For local development, infer the version to match from the package.
+    if "dev" in release or "rc" in release:
+        version_match = "dev"
+        # We want to keep the relative reference if we are in dev mode
+        # but we want the whole url if we are effectively in a released version
+        json_url = "_static/switcher.json"
+    else:
+        version_match = f"v{release}"
+elif version_match == "stable":
+    version_match = f"v{release}"
+
 # Pages entry without primary (left) sidebar
 
 html_sidebars = {
@@ -152,7 +173,6 @@ html_sidebars = {
     "index": []
 }
 
-
 html_theme_options = {
     "external_links": [
         {
@@ -212,8 +232,8 @@ html_theme_options = {
     "navbar_align": "right",
     "show_nav_level": 1,
     "announcement": "Welcome to new site for BeagleBoard.org docs!",
-    # "show_version_warning_banner": True,
-    "navbar_center": ["navbar-nav"],
+    "show_version_warning_banner": True,
+    "navbar_center": ["version-switcher", "navbar-nav"],
     "navbar_start": ["navbar-logo"],
     "navbar_end": ["theme-switcher", "navbar-icon-links"],
     # "navbar_persistent": ["search-button"],
@@ -224,6 +244,10 @@ 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,
+    },
 }
 
 # parse version from 'VERSION' file
-- 
GitLab