Do not show badge for master only repos
If a repo has no stable branches, we do not need to show the badge, disable it automatically. Also, disable it for releasenotes, api-guide and api-ref. These documents are always published from master and are versionless. This avoids changing most of the repositories to disable the badge. Change-Id: I063af45e40bd41e27334638e2cf65ca0c9119e63
This commit is contained in:
parent
f5051b4323
commit
e72301e141
@ -140,8 +140,10 @@ with documentation available. By default it is set to ``None``::
|
||||
document with internal versioning.
|
||||
|
||||
|
||||
By default, a badge is displayed showing which the latest OpenStack
|
||||
release is. You can disable the badge with::
|
||||
A badge pointing out the support status of a document is shown now
|
||||
for repositories that have ``stable/`` branches. The badge is not
|
||||
displayed for api-ref, api-guide and releasenotes documents. It
|
||||
can be disabled with the ``display_badge`` html theme option::
|
||||
|
||||
html_theme_options = {
|
||||
# ...
|
||||
|
@ -34,6 +34,21 @@ _html_context_data = None
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _has_stable_branches():
|
||||
try:
|
||||
repo = dulwich.repo.Repo.discover()
|
||||
except dulwich.repo.NotGitRepository:
|
||||
return False
|
||||
|
||||
refs = repo.get_refs()
|
||||
for ref in refs.keys():
|
||||
ref = ref.decode('utf-8')
|
||||
if ref.startswith('refs/remotes/origin/stable'):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def _get_other_versions(app):
|
||||
if not app.config.html_theme_options.get('show_other_versions', False):
|
||||
return []
|
||||
@ -117,6 +132,21 @@ def _html_page_context(app, pagename, templatename, context, doctree):
|
||||
_html_context_data['bug_tag'] = bug_tag
|
||||
_html_context_data['series'] = _get_series_name()
|
||||
|
||||
# Do not show the badge in these cases:
|
||||
# - display_badge is false
|
||||
# - repo has no stable/ branches
|
||||
# - directory is named api-guide, api-ref, or releasenotes
|
||||
if not app.config.html_theme_options.get('display_badge', True):
|
||||
_html_context_data['display_badge'] = False
|
||||
elif _has_stable_branches():
|
||||
doc_parts = os.path.abspath(app.srcdir).split(os.sep)[-2:]
|
||||
if doc_parts[0] in ('api-guide', 'api-ref', 'releasenotes'):
|
||||
_html_context_data['display_badge'] = False
|
||||
else:
|
||||
_html_context_data['display_badge'] = True
|
||||
else:
|
||||
_html_context_data['display_badge'] = False
|
||||
|
||||
context.update(_html_context_data)
|
||||
context['other_versions'] = _get_other_versions(app)
|
||||
|
||||
|
@ -94,7 +94,7 @@ ga('send', 'pageview');
|
||||
{% include 'footer.html' %}
|
||||
{% include 'script_footer.html' %}
|
||||
{% block script_footer %}{% endblock %}
|
||||
{% if theme_display_badge %}
|
||||
{% if display_badge %}
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function(){
|
||||
|
||||
|
7
releasenotes/notes/badge-6f8713da36a7e570.yaml
Normal file
7
releasenotes/notes/badge-6f8713da36a7e570.yaml
Normal file
@ -0,0 +1,7 @@
|
||||
features:
|
||||
- |
|
||||
A badge pointing out the support status of a document is shown now
|
||||
for repositories that have ``stable/`` branches. The badge is not
|
||||
displayed for api-ref, api-guide and releasenotes documents. It
|
||||
can be disabled with the ``display_badge`` html theme option.
|
||||
|
Loading…
Reference in New Issue
Block a user