Skip to content

Commit 7e06c4f

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

File tree

5 files changed

+126
-0
lines changed

5 files changed

+126
-0
lines changed

Makefile

Lines changed: 12 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,17 @@ help:
3536
html:
3637
$(Q)$(SPHINXBUILD) -t $(DOC_TAG) -b html -d $(BUILDDIR)/doctrees $(SOURCEDIR) $(BUILDDIR)/html $(SPHINXOPTS) $(O)
3738

39+
multiversion:
40+
@original_branch=$$(git symbolic-ref --short HEAD); \
41+
echo "Building documentation for supported versions: $(SUPPORTED_VERSIONS)"; \
42+
for version in $(SUPPORTED_VERSIONS); do \
43+
echo "Building $$version..."; \
44+
git checkout $$version && \
45+
$(SPHINXBUILD) -b html $(SPHINXOPTS) . $(BUILDDIR)/html/$$version || exit 1; \
46+
done; \
47+
git checkout $$original_branch; \
48+
echo "<html><head><meta http-equiv=\"refresh\" content=\"0; url=master/index.html\" /></head></html>" > $(BUILDDIR)/html/index.html
49+
3850
# Autobuild the docs on changes
3951

4052
autobuild:

_themes/otc_tcs_sphinx_theme/static/tcs_theme.css

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

_themes/otc_tcs_sphinx_theme/static/tcs_theme.js

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

conf.py

Lines changed: 1 addition & 0 deletions
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']

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)