Skip to content

Commit 7085601

Browse files
committed
There didn't seem to be a way to convince sphinx-multiversion to use
the correct version in the breadcrumbs. So this changes the html_title (which is the first thing displayed in the breadcrumbs) to "PSI/J" and inserts the version dropdown after that. This also seems to make better sense from a usability perspective since there is only one control to both display and change the version.
1 parent a6e081d commit 7085601

File tree

5 files changed

+48
-22
lines changed

5 files changed

+48
-22
lines changed

docs/_templates/layout.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
{{ super() }}
1717
{% endblock %}
1818

19+
{% block rootrellink %}
20+
<li><a href="{{ pathto(theme_roottarget) }}">{{shorttitle|e}}</a>{% if versions %}{% include "../../web/_includes/versionselect.html" %}{% endif %}{{reldelim1}}</li>
21+
{% endblock %}
22+
23+
1924
{% block footer %}
2025
{{ super() }}
2126

docs/_templates/versioning.html

Lines changed: 0 additions & 4 deletions
This file was deleted.

docs/conf.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,25 @@
3535
]
3636

3737
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}'
38+
templates_path = ['_templates']
39+
# Unfortunately sphinx-multiversion does not properly deal with
40+
# setting the title to the proper version. You either get some
41+
# default like "0.0.1" or you get whatever the current conf.py
42+
# sets (i.e., the latest version).
43+
# See, e.g., https://github.com/Holzhaus/sphinx-multiversion/issues/61
44+
#
45+
# But we already have the version selector that displays the version,
46+
# so we can display that where the broken version would otherwise
47+
# have appeared.
48+
html_title = "PSI/J"
49+
# Multi-version
50+
smv_branch_whitelist = '^matchmeifyoucan$'
51+
smv_remote_whitelist = None
52+
smv_released_pattern = r'^\d+\.\d+\.\d+(\..*)?$'
53+
smv_outputdir_format = 'v/{ref.name}'
4454

4555

4656
html_sidebars = {'**': ['globaltoc.html', 'relations.html', 'sourcelink.html', 'searchbox.html']}
47-
if web_docs:
48-
html_sidebars['**'].insert(0, 'versioning.html')
4957

5058
# These are needed for the dhtml trickery
5159
html_static_path = ["_static"]
@@ -67,17 +75,23 @@
6775
autodoc_typehints = "description"
6876
autodoc_typehints_format = "short"
6977

78+
release = None
79+
version = None
80+
src_dir = None
81+
82+
def read_version(docs_dir):
83+
global release, version, src_dir
84+
src_dir = os.path.abspath(os.path.join(docs_dir, '../src'))
7085

71-
script_dir = os.path.normpath(os.path.dirname(__file__))
72-
src_dir = os.path.abspath(os.path.join(script_dir, '../src'))
86+
sys.path.insert(0, src_dir)
7387

74-
print(src_dir + "/")
88+
import psij
89+
release = psij.__version__
90+
version = release
7591

76-
sys.path.insert(0, src_dir)
7792

78-
import psij
79-
release = psij.__version__
80-
version = release
93+
my_dir = os.path.normpath(os.path.dirname(__file__))
94+
read_version(my_dir)
8195

8296
intersphinx_mapping = {
8397
'python': ('https://docs.python.org/3', None),
@@ -90,6 +104,7 @@
90104

91105
# run api doc
92106
def run_apidoc(sphinx):
107+
read_version(sphinx.srcdir) # this sets src_dir based on the version being compiled
93108
output_path = os.path.join(sphinx.srcdir, '.generated')
94109
main(['-f', '-o', output_path, src_dir])
95110

web/_includes/versionselect.html

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

web/style.css

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,18 @@ pre {
235235
/*** Versioning ***/
236236

237237
#version-selector {
238-
margin-top: 4pt;
239-
margin-right: 4pt;
238+
display: inline-block;
239+
margin: 0;
240+
}
241+
242+
#version-selector .v-input__control, #version-selector .v-input__slot,
243+
#version-selector .v-select__slot, #version-selector .v-select__selection {
244+
width: fit-content;
245+
text-overflow: none;
246+
}
247+
248+
#version-selector .v-input__control {
249+
height: 18pt;
240250
}
241251

242252
#version-selector .v-text-field__prefix {

0 commit comments

Comments
 (0)