Skip to content

Commit babca12

Browse files
committed
Added multiple versions to the documentation.
There are multiple parts to this: - sphinx-multiversion is used to build docs from all release tags when doing a web build; resulting docs are in `/docs/v/<version>`. - `/docs/index.html` now has some JS to figure out the latest version and redirect to it - a version selector is added to the sidebar - there is some JS to collapse all `x.y.z(*)` into `x.y.z` and map `x.y.z` to the latest `x.y.z(*)` (e.g., `0.1.0` -> `0.1.0post2`; basically we use the latest post release available and hide the others with the same version.
1 parent 5cbeddb commit babca12

File tree

12 files changed

+288
-14
lines changed

12 files changed

+288
-14
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ docs:
5656
.PHONY: web-docs
5757
web-docs:
5858
rm -rf docs/.generated
59-
sphinx-build -W -b html -D html_theme='cloud' -D templates_path='_templates' docs docs/.web-build/
59+
rm -rf docs/.web-build
60+
PSIJ_WEB_DOCS=1 sphinx-multiversion docs docs/.web-build
6061

6162
.PHONY: style
6263
style:

docs/_templates/versioning.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{% if versions %}
2+
{% include "../../web/_includes/versionselect.html" %}
3+
{% endif %}
4+

docs/conf.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,22 @@
88
import sphinx_rtd_theme
99
from sphinx.ext.apidoc import main
1010

11+
web_docs = False
12+
if 'PSIJ_WEB_DOCS' in os.environ:
13+
web_docs = True
14+
1115
needs_sphinx = '1.6'
1216

1317
# Set Sphinx variables
1418
master_doc = 'index'
1519

1620
project = u'PSI/J'
1721
copyright = u'The ExaWorks Team'
18-
19-
html_theme = 'sphinx_rtd_theme'
20-
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
22+
if web_docs:
23+
html_theme = 'cloud'
24+
else:
25+
html_theme = 'sphinx_rtd_theme'
26+
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
2127
html_favicon = 'favicon.ico'
2228
autoclass_content = 'both'
2329
add_module_names = False
@@ -28,7 +34,18 @@
2834
('py:class', 'distutils.version.Version')
2935
]
3036

37+
if web_docs:
38+
templates_path = ['_templates']
39+
# Multi-version
40+
smv_branch_whitelist = '^mathcmeifyoucan$'
41+
smv_remote_whitelist = None
42+
smv_released_pattern = r'^\d+\.\d+\.\d+(\..*)?$'
43+
smv_outputdir_format = 'v/{ref.name}'
44+
45+
3146
html_sidebars = {'**': ['globaltoc.html', 'relations.html', 'sourcelink.html', 'searchbox.html']}
47+
if web_docs:
48+
html_sidebars['**'].insert(0, 'versioning.html')
3249

3350
# These are needed for the dhtml trickery
3451
html_static_path = ["_static"]
@@ -44,6 +61,9 @@
4461
'sphinx.ext.viewcode',
4562
]
4663

64+
if web_docs:
65+
extensions.append('sphinx_multiversion')
66+
4767
autodoc_typehints = "description"
4868
autodoc_typehints_format = "short"
4969

@@ -69,10 +89,8 @@
6989
# Copied from https://github.com/readthedocs/readthedocs.org/issues/1139
7090

7191
# run api doc
72-
def run_apidoc(_):
73-
output_path = os.path.join(script_dir, '.generated')
74-
print(f"OUTPUT PATH = {output_path}")
75-
#exclusions = [os.path.join(src_dir, 'setup.py'),]
92+
def run_apidoc(sphinx):
93+
output_path = os.path.join(sphinx.srcdir, '.generated')
7694
main(['-f', '-o', output_path, src_dir])
7795

7896
# launch setup

requirements-docs.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ six
1010
Sphinx==4.5.0
1111
sphinx_rtd_theme
1212
sphinx-tabs
13+
sphinx-multiversion
1314

1415
# For the web version of the docs
1516
cloud_sptheme == 1.10.1.post20200504175005

web/_includes/head.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@
1616
<link rel="stylesheet"
1717
href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.4.0/styles/base16/tender.min.css">
1818
<script src="https://kit.fontawesome.com/0f2ef02e2b.js" crossorigin="anonymous"></script>
19+
<script src="{{ site.baseurl }}/versions.js"></script>
20+
<script src="{{ site.baseurl }}/versioning.js"></script>

web/_includes/versionselect.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div id="version-selector">
2+
<v-select prefix="Version" :items="getSortedVersionLabels()" @change="setVersion" v-model="version"></v-select>
3+
</div>

web/_includes/vueinit.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
el: '#psij-app',
55
vuetify: new Vuetify(),
66
data: {
7-
maintabs: {{ page.tab }}
7+
maintabs: {{ page.tab }},
8+
version: getCurrentVersion()
9+
},
10+
methods: {
11+
getSortedVersionLabels: getSortedVersionLabels,
12+
setVersion: setVersion
813
}
914
});
1015

web/build.sh

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,26 @@ if [ "$1" != "--quick" ]; then
1818
cp -r docs/.web-build/. web-build/docs/
1919
fi
2020

21-
cp -r web/. web-build/
22-
cp web/*.css web-build/docs/
21+
22+
cp -r web/_layouts/ web-build/
23+
cp -r web/_includes/ web-build/
24+
25+
echo -n "var DOC_VERSIONS_RAW = [" >web-build/versions.js
26+
for V in `ls web-build/docs/v`; do
27+
echo "Patching version $V"
28+
cp -r web/docs/_static web-build/docs/v/$V/
29+
30+
echo "\"$V\", " >>web-build/versions.js
31+
done
32+
echo "]" >>web-build/versions.js
33+
34+
for F in `ls web/*`; do
35+
if [ -f "$F" ]; then
36+
cp "$F" web-build/
37+
fi
38+
done
39+
40+
cp web/docs/index.html web-build/docs/
2341

2442
rm -f web-build/*.sh
25-
rm -f web-build/README
43+
rm -f web-build/README

web/docs/_static/cloud.css

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ ul, ol {
4040

4141
div.relbar-top {
4242
background-color: #e0e0e0;
43+
border-bottom: 1px solid var(--color-fg-lines);
4344
}
4445

4546

@@ -112,7 +113,7 @@ div.body {
112113
}
113114

114115
div.sphinxsidebar {
115-
margin-top: 32pt;
116+
margin-top: 4pt;
116117
width: 3in;
117118
font-size: 90%;
118119
line-height: 1.25em;
@@ -123,7 +124,7 @@ div.document.sidebar-hidden div.sphinxsidebar {
123124
}
124125

125126
div.sphinxsidebarwrapper {
126-
padding: 1em 0 0 10px;
127+
padding: 0 0 0 10px;
127128
}
128129

129130
div.sphinxsidebar h3, div.sphinxsidebar h4 {

web/docs/index.html

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
title: PSI/J - Python
3+
layout: raw
4+
tab: 2
5+
---
6+
7+
<!DOCTYPE html>
8+
<html>
9+
<head>
10+
<title>Documentation - PSI/J - Python</title>
11+
<script src="{{ site.baseurl }}/versions.js"></script>
12+
<script src="{{ site.baseurl }}/versioning.js"></script>
13+
</head>
14+
<body>
15+
<script type="application/javascript">
16+
var latest = getLatestVersion();
17+
document.write("Redirecting to <a href=\"v/" + latest + "\">Version " + latest + " documentation</a>");
18+
var loc = window.location.href;
19+
if (loc.endsWith(".html")) {
20+
loc = loc.substring(0, loc.lastIndexOf("/"));
21+
}
22+
if (loc.endsWith("/")) {
23+
loc = loc.substring(0, loc.length - 1);
24+
}
25+
window.location = loc + "/v/" + latest + "/";
26+
</script>
27+
</body>
28+
</html>
29+

0 commit comments

Comments
 (0)