Skip to content

Commit b7f7a60

Browse files
committed
Add option to switch docs version
1 parent 89a5d66 commit b7f7a60

File tree

3 files changed

+59
-20
lines changed

3 files changed

+59
-20
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ build/
88
# vale configs and intermediary data
99
.github/styles/*
1010
!.github/styles/config
11+
/.venv
12+
.DS_Store

_templates/layout.html

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
11
{% extends "!layout.html" %}
2-
{%- block extrahead %}
3-
<script src="https://www.ti.com/assets/js/headerfooter/analytics.js" type="text/javascript" charset="utf-8"></script>
4-
{{ super() }}
2+
{%- block extrahead %}
3+
<script src="https://www.ti.com/assets/js/headerfooter/analytics.js" type="text/javascript" charset="utf-8"></script>
4+
{{ super() }}
55
{% endblock %}
66
{%- block sidebartitle %}
7-
{# the logo helper function was removed in Sphinx 6 and deprecated since Sphinx 4 #}
8-
{# the master_doc variable was renamed to root_doc in Sphinx 4 (master_doc still exists in later Sphinx versions) #}
9-
{%- set _logo_url = logo_url|default(pathto('_static/' + (logo or ""), 1)) %}
10-
{%- set _root_doc = root_doc|default(master_doc) %}
11-
<a href="{{ pathto(_root_doc) }}"{% if not theme_logo_only %} class="icon icon-home"{% endif %}>
12-
{% if not theme_logo_only %}{{ project }}{% endif %}
13-
{%- if logo or logo_url %}
14-
<img src="{{ _logo_url }}" class="logo" alt="{{ _('Logo') }}"/>
15-
{%- endif %}
16-
</a>
17-
{%- set nav_version = version %}
18-
{%- if nav_version %}
19-
<div class="version">
20-
{{ nav_version }}
21-
</div>
7+
{# the logo helper function was removed in Sphinx 6 and deprecated since Sphinx 4 #}
8+
{# the master_doc variable was renamed to root_doc in Sphinx 4 (master_doc still exists in later Sphinx versions) #}
9+
{%- set _logo_url = logo_url|default(pathto('_static/' + (logo or ""), 1)) %}
10+
{%- set _root_doc = root_doc|default(master_doc) %}
11+
<a href="{{ pathto(_root_doc) }}" {% if not theme_logo_only %} class="icon icon-home" {% endif %}>
12+
{% if not theme_logo_only %}{{ project }}{% endif %}
13+
{%- if logo or logo_url %}
14+
<img src="{{ _logo_url }}" class="logo" alt="{{ _('Logo') }}" />
2215
{%- endif %}
23-
{%- include "searchbox.html" %}
24-
{% endblock %}
16+
</a>
17+
{%- set nav_version = version %}
18+
{%- if nav_version and versions %}
19+
<div class="version">
20+
<select id="version-selector"
21+
onchange="location.href = location.href.replace(/\/docs\/[^\/]+\//, '/docs/' + this.value + '/');"
22+
style="background-color: white; color: black; border: 1px solid #d9d9d9; padding: 5px; border-radius: 3px;">
23+
{% for v in versions %}
24+
<option value="{{ v }}" {% if v==nav_version %}selected{% endif %}>{{ v }}</option>
25+
{% endfor %}
26+
</select>
27+
</div>
28+
{%- elif nav_version %}
29+
<div class="version">
30+
{{ nav_version }}
31+
</div>
32+
{%- endif %}
33+
{%- include "searchbox.html" %}
34+
{% endblock %}

conf.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import sys
1717
import os
1818
import importlib
19+
import subprocess
1920
from datetime import datetime
2021

2122
# If extensions (or modules to document with autodoc) are in another directory,
@@ -204,8 +205,34 @@
204205
"github_repo": "processor-sdk-doc",
205206
"github_version": "master",
206207
"conf_py_path": "/source/",
208+
"versions": [],
207209
}
208210

211+
def get_versions():
212+
versions = ["master"]
213+
try:
214+
cmd = ["git", "ls-remote", "--tags", "--heads", "https://github.com/TexasInstruments/processor-sdk-doc"]
215+
output = subprocess.check_output(cmd).decode('utf-8').splitlines()
216+
tags = []
217+
for line in output:
218+
parts = line.split()
219+
if len(parts) == 2:
220+
ref = parts[1]
221+
if ref.startswith("refs/tags/"):
222+
tag = ref.replace("refs/tags/", "")
223+
tags.append(tag)
224+
225+
# Sort tags descending
226+
tags.sort(reverse=True)
227+
versions.extend(tags)
228+
except Exception as e:
229+
print(f"Error fetching versions: {e}")
230+
# Fallback
231+
versions = ["master"]
232+
return versions
233+
234+
html_context["versions"] = get_versions()
235+
209236
# -- Options for LaTeX output ---------------------------------------------
210237

211238
latex_elements = {

0 commit comments

Comments
 (0)