From b7f7a60f228a00b2ef594eafebcad17df7d04069 Mon Sep 17 00:00:00 2001 From: Andrei Aldea Date: Tue, 25 Nov 2025 09:42:46 -0600 Subject: [PATCH] Add option to switch docs version --- .gitignore | 2 ++ _templates/layout.html | 50 +++++++++++++++++++++++++----------------- conf.py | 27 +++++++++++++++++++++++ 3 files changed, 59 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 761bc0cea..a5f6745a0 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ build/ # vale configs and intermediary data .github/styles/* !.github/styles/config +/.venv +.DS_Store diff --git a/_templates/layout.html b/_templates/layout.html index 32ba3283b..0d21a2677 100644 --- a/_templates/layout.html +++ b/_templates/layout.html @@ -1,24 +1,34 @@ {% extends "!layout.html" %} -{%- block extrahead %} - - {{ super() }} +{%- block extrahead %} + +{{ super() }} {% endblock %} {%- block sidebartitle %} - {# the logo helper function was removed in Sphinx 6 and deprecated since Sphinx 4 #} - {# the master_doc variable was renamed to root_doc in Sphinx 4 (master_doc still exists in later Sphinx versions) #} - {%- set _logo_url = logo_url|default(pathto('_static/' + (logo or ""), 1)) %} - {%- set _root_doc = root_doc|default(master_doc) %} - - {% if not theme_logo_only %}{{ project }}{% endif %} - {%- if logo or logo_url %} - - {%- endif %} - - {%- set nav_version = version %} - {%- if nav_version %} -
- {{ nav_version }} -
+{# the logo helper function was removed in Sphinx 6 and deprecated since Sphinx 4 #} +{# the master_doc variable was renamed to root_doc in Sphinx 4 (master_doc still exists in later Sphinx versions) #} +{%- set _logo_url = logo_url|default(pathto('_static/' + (logo or ""), 1)) %} +{%- set _root_doc = root_doc|default(master_doc) %} + + {% if not theme_logo_only %}{{ project }}{% endif %} + {%- if logo or logo_url %} + {%- endif %} - {%- include "searchbox.html" %} -{% endblock %} + +{%- set nav_version = version %} +{%- if nav_version and versions %} +
+ +
+{%- elif nav_version %} +
+ {{ nav_version }} +
+{%- endif %} +{%- include "searchbox.html" %} +{% endblock %} \ No newline at end of file diff --git a/conf.py b/conf.py index fea391f4b..e38768372 100644 --- a/conf.py +++ b/conf.py @@ -16,6 +16,7 @@ import sys import os import importlib +import subprocess from datetime import datetime # If extensions (or modules to document with autodoc) are in another directory, @@ -204,8 +205,34 @@ "github_repo": "processor-sdk-doc", "github_version": "master", "conf_py_path": "/source/", + "versions": [], } +def get_versions(): + versions = ["master"] + try: + cmd = ["git", "ls-remote", "--tags", "--heads", "https://github.com/TexasInstruments/processor-sdk-doc"] + output = subprocess.check_output(cmd).decode('utf-8').splitlines() + tags = [] + for line in output: + parts = line.split() + if len(parts) == 2: + ref = parts[1] + if ref.startswith("refs/tags/"): + tag = ref.replace("refs/tags/", "") + tags.append(tag) + + # Sort tags descending + tags.sort(reverse=True) + versions.extend(tags) + except Exception as e: + print(f"Error fetching versions: {e}") + # Fallback + versions = ["master"] + return versions + +html_context["versions"] = get_versions() + # -- Options for LaTeX output --------------------------------------------- latex_elements = {