diff --git a/doc/source/conf.py b/doc/source/conf.py index 9487fcc..91a5162 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -69,9 +69,18 @@ copyright = u'2015-2017, OpenStack Contributors' # "version" and "release" are used by the "log-a-bug" feature # # The short X.Y version. -version = '1.0' +#version = '1.0' # The full version, including alpha/beta/rc tags. -release = '1.0' +#release = '1.0' +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +from openstackdocstheme.version import version_info +# The full version, including alpha/beta/rc tags. +release = version_info.release_string() +# The short X.Y version. +version = version_info.version_string() # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -128,6 +137,7 @@ html_theme = 'openstackdocs' # Otherwise, the list of links for the User and Ops docs # appear in the sidebar dropdown menu. #html_theme_options = {"sidebar_dropdown": "api_ref"} +html_theme_options = {'show_other_versions': True} # Add any paths that contain custom themes here, relative to this directory. # html_theme_path = [] diff --git a/openstackdocstheme/__init__.py b/openstackdocstheme/__init__.py index 176219f..08f29f8 100644 --- a/openstackdocstheme/__init__.py +++ b/openstackdocstheme/__init__.py @@ -13,12 +13,41 @@ # under the License. import os +import string import subprocess _giturl = 'https://git.openstack.org/cgit/{}/tree/doc/source' _html_context_data = None +def _get_other_versions(app): + if not app.config.html_theme_options.get('show_other_versions', False): + return [] + + git_cmd = ["git", "tag", "--merged"] + try: + raw_version_list = subprocess.Popen( + git_cmd, stdout=subprocess.PIPE).communicate()[0] + raw_version_list = raw_version_list.decode("utf-8") + except UnicodeDecodeError: + app.warn('Cannot decode the list based on utf-8 encoding. ' + 'Not setting "other_versions".') + raw_version_list = u'' + except OSError: + app.warn('Cannot get tags from git repository, or no merged tags. ' + 'Not setting "other_versions".') + raw_version_list = u'' + + # grab last five that start with a number and reverse the order + _tags = [t.strip("'") for t in raw_version_list.split('\n')] + other_versions = [ + t for t in _tags if t and t[0] in string.digits + # Don't show alpha, beta or release candidate tags + and 'rc' not in t and 'a' not in t and 'b' not in t + ][:-5:-1] + return other_versions + + def builder_inited(app): theme_dir = os.path.join(os.path.dirname(__file__), 'theme') app.info('Using openstackdocstheme Sphinx theme from %s' % theme_dir) @@ -65,6 +94,7 @@ def _html_page_context(app, pagename, templatename, context, doctree): _html_context_data['bug_tag'] = bug_tag context.update(_html_context_data) + context['other_versions'] = _get_other_versions(app) def setup(app): diff --git a/openstackdocstheme/theme/openstackdocs/layout.html b/openstackdocstheme/theme/openstackdocs/layout.html index cf0b090..e7177e6 100644 --- a/openstackdocstheme/theme/openstackdocs/layout.html +++ b/openstackdocstheme/theme/openstackdocs/layout.html @@ -38,6 +38,19 @@ ga('send', 'pageview'); {% include 'titlerow.html' %}
updated: {{ last_updated }}
+ {%- block otherversions %} + {%- if other_versions %} +
+ {{ _('version') }} +
+

Current

+ {%- for ver in other_versions: %} +

{{ ver }}

+ {%- endfor %} +
+
+ {%- endif %} + {%- endblock %}
diff --git a/openstackdocstheme/theme/openstackdocs/static/css/combined.css b/openstackdocstheme/theme/openstackdocs/static/css/combined.css index d366cfe..b090404 100644 --- a/openstackdocstheme/theme/openstackdocs/static/css/combined.css +++ b/openstackdocstheme/theme/openstackdocs/static/css/combined.css @@ -3813,6 +3813,34 @@ a.overview-btn.contribute-btn:hover { a.overview-btn.contribute-btn i { margin-left: 10px; } +/*------------------------------------*\ + Docs Version Dropdown +\*------------------------------------*/ + +.version-dropdown { + position: relative; + float: right; + display: inline-block; + border: solid 1px; + padding: 5px; +} + +.version-dropdown-content { + display: none; + position: absolute; + background-color: #f9f9f9; + min-width: 160px; + box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); + padding: 12px 16px; + top: 25px; + right: 5px; + z-index: 1; +} + +.version-dropdown:hover .version-dropdown-content { + display: block; +} + /*End Docs Main*/ /*Docs Book View*/ .docs-book-wrapper, .docs-search-wrapper { @@ -4080,6 +4108,10 @@ li.docs-has-sub.open:before { float: left; padding: 5px; } +.docs-versioned { + float: right; + padding: 5px; } + a.docs-edit { float: right; color: #9eb5c3; } diff --git a/openstackdocstheme/theme/openstackdocs/theme.conf b/openstackdocstheme/theme/openstackdocs/theme.conf index 9991b09..ba18e8b 100644 --- a/openstackdocstheme/theme/openstackdocs/theme.conf +++ b/openstackdocstheme/theme/openstackdocs/theme.conf @@ -8,3 +8,4 @@ analytics_tracking_code = UA-17511903-1 sidebar_mode = toctree display_toc = True sidebar_dropdown = os_docs +show_other_versions = False