Skip to content

Commit 8857d2f

Browse files
authored
Merge pull request #63 from QuLogic/release-navbar
2 parents e0d42e5 + ce9a3a9 commit 8857d2f

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

mpl_sphinx_theme/__init__.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,21 @@ def get_html_theme_path():
3333

3434
def setup_html_page_context(app, pagename, templatename, context, doctree):
3535
"""Add a mpl_path template function."""
36+
# Pick link setting based on release mode. Theme users may specify either:
37+
# 1. a single string indicating the mode for navbar links;
38+
# 2. a tuple of two strings, the first being the mode for development, and
39+
# the second being the mode for release.
40+
# Release mode is determined by specifying the 'release' tag during build.
3641
navbar_links = context['theme_navbar_links']
37-
if navbar_links not in ['internal', 'absolute', 'server-stable']:
42+
if not isinstance(navbar_links, tuple):
43+
# Allow a single string for backwards compatibility.
44+
navbar_links = (navbar_links, navbar_links)
45+
if (len(navbar_links) != 2 or
46+
any(opt not in ['internal', 'absolute', 'server-stable']
47+
for opt in navbar_links)):
3848
raise ValueError(f'Invalid navbar_links theme option: {navbar_links}')
49+
navbar_links = (navbar_links[1] if app.tags.has('release') else
50+
navbar_links[0])
3951

4052
def mpl_path(path):
4153
if navbar_links == 'internal':

0 commit comments

Comments
 (0)