Skip to content

Commit 111edc8

Browse files
Added multiversion support for master.
Signed-off-by: Leander Stephen D'Souza <[email protected]>
1 parent 8619935 commit 111edc8

File tree

5 files changed

+145
-1
lines changed

5 files changed

+145
-1
lines changed

Makefile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ BUILDDIR = _build
1717
DOC_TAG ?= development
1818
RELEASE ?= latest
1919
PUBLISHDIR = /tmp/navigation2
20+
SUPPORTED_VERSIONS = master
2021

2122
# Put it first so that "make" without argument is like "make help".
2223
help:
@@ -35,6 +36,31 @@ help:
3536
html:
3637
$(Q)$(SPHINXBUILD) -t $(DOC_TAG) -b html -d $(BUILDDIR)/doctrees $(SOURCEDIR) $(BUILDDIR)/html $(SPHINXOPTS) $(O)
3738

39+
multiversion:
40+
@(\
41+
if ! git diff-index --quiet HEAD --; then \
42+
git stash push -q -m "multiversion build temporary stash"; \
43+
echo "Changes stashed"; \
44+
fi; \
45+
)
46+
@(\
47+
original_branch=$$(git symbolic-ref --short HEAD); \
48+
echo "Building documentation for supported versions: $(SUPPORTED_VERSIONS)"; \
49+
for version in $(SUPPORTED_VERSIONS); do \
50+
echo "Building $$version..."; \
51+
git checkout -q $$version && \
52+
$(SPHINXBUILD) -b html $(SPHINXOPTS) . $(BUILDDIR)/html/$$version || exit 1; \
53+
done; \
54+
git checkout -q $$original_branch; \
55+
echo "<html><head><meta http-equiv=\"refresh\" content=\"0; url=master/index.html\" /></head></html>" > $(BUILDDIR)/html/index.html \
56+
)
57+
@(\
58+
if git stash list | grep -q "multiversion build temporary stash"; then \
59+
git stash pop -q; \
60+
echo "Changes restored from stash"; \
61+
fi \
62+
)
63+
3864
# Autobuild the docs on changes
3965

4066
autobuild:

_themes/otc_tcs_sphinx_theme/static/tcs_theme.css

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,67 @@ th,td {
170170
display: inline;
171171
margin-left: 20px;
172172
}
173+
174+
/* Version dropdown styles */
175+
.version-dropdown {
176+
position: relative;
177+
display: inline-block;
178+
width: 100%;
179+
margin-bottom: 20px;
180+
border: 2px solid #ccc;
181+
border-radius: 4px;
182+
}
183+
184+
.version-btn {
185+
background-color: #2980b9;
186+
color: white;
187+
padding: 10px 15px;
188+
font-size: 16px;
189+
border: none;
190+
cursor: pointer;
191+
width: 100%;
192+
text-align: left;
193+
border-radius: 4px;
194+
font-family: inherit;
195+
}
196+
197+
.version-btn:hover {
198+
background-color: #3498db;
199+
}
200+
201+
.version-caret {
202+
float: right;
203+
}
204+
205+
.version-dropdown-content {
206+
display: none;
207+
position: absolute;
208+
background-color: #f9f9f9;
209+
min-width: 160px;
210+
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
211+
z-index: 1;
212+
width: 100%;
213+
border-radius: 4px;
214+
overflow: hidden;
215+
text-align: left;
216+
}
217+
218+
.version-dropdown-content a {
219+
color: #333;
220+
padding: 12px 16px;
221+
text-decoration: none;
222+
display: block;
223+
background-color: #f9f9f9;
224+
}
225+
226+
.version-dropdown-content a:hover {
227+
background-color: #ddd;
228+
}
229+
230+
.version-dropdown-content.show {
231+
display: block;
232+
}
233+
234+
.wy-side-nav-search {
235+
margin-top: 0;
236+
}

_themes/otc_tcs_sphinx_theme/static/tcs_theme.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,55 @@ for (i = 0; i < contents.length; i++) {
4848
}
4949
}
5050
}
51+
52+
document.addEventListener('DOMContentLoaded', function() {
53+
const supportedVersions = ['rolling'];
54+
const versionDropdown = document.createElement('div');
55+
versionDropdown.className = 'version-dropdown';
56+
57+
// Detect current version from URL
58+
const currentVersion = supportedVersions.find(version =>
59+
window.location.pathname.includes(`/${version}/`)
60+
) || 'rolling'; // Default to rolling if none found
61+
62+
const dropdownBtn = document.createElement('button');
63+
dropdownBtn.className = 'version-btn';
64+
dropdownBtn.innerHTML = `${currentVersion} <span class="version-caret">▼</span>`;
65+
66+
const dropdownContent = document.createElement('div');
67+
dropdownContent.className = 'version-dropdown-content';
68+
69+
supportedVersions.forEach(version => {
70+
const link = document.createElement('a');
71+
72+
// Replace current version in path with selected version
73+
const newPath = window.location.pathname.replace(
74+
new RegExp(`/(${supportedVersions.join('|')})/`),
75+
`/${version}/`
76+
);
77+
78+
link.href = newPath;
79+
link.textContent = version;
80+
dropdownContent.appendChild(link);
81+
});
82+
83+
versionDropdown.appendChild(dropdownBtn);
84+
versionDropdown.appendChild(dropdownContent);
85+
86+
const searchBox = document.querySelector('.wy-side-nav-search');
87+
const logo = document.querySelector('.wy-side-nav-search > a');
88+
89+
if (searchBox && logo) {
90+
searchBox.insertBefore(versionDropdown, logo.nextSibling);
91+
}
92+
// Toggle dropdown
93+
dropdownBtn.addEventListener('click', function(e) {
94+
e.stopPropagation();
95+
dropdownContent.classList.toggle('show');
96+
});
97+
98+
// Close dropdown when clicking outside
99+
document.addEventListener('click', function() {
100+
dropdownContent.classList.remove('show');
101+
});
102+
});

conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
'sphinx.ext.extlinks',
4040
'sphinx.ext.graphviz',
4141
'sphinxcontrib.plantuml',
42+
'sphinx_multiversion',
4243
]
4344

4445
myst_enable_extensions = ['colon_fence']
@@ -124,7 +125,7 @@
124125
'canonical_url': '',
125126
'analytics_id': 'G-EVD5Z6G6NH',
126127
'logo_only': False,
127-
'display_version': True,
128+
'display_version': False,
128129
'prev_next_buttons_location': 'None',
129130
# Toc options
130131
'collapse_navigation': False,

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ sphinx_rtd_theme==2.0.0
77
sphinx-autobuild
88
sphinx==5.3.0
99
sphinxcontrib-plantuml
10+
sphinx-multiversion

0 commit comments

Comments
 (0)