From 16ea4f4e7f4ec6c874423bc918a0f163c3380f7d Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Wed, 13 Jun 2018 15:36:00 -0300 Subject: [PATCH] Override versions.html template for specific RTD functionality Sphinx RTD theme uses a `versions.html` template to generate the version menu if `READTHEDOCS` variable is True. Since this is something specific to Read the Docs and that variable is going to be removed soon from the theme, we are overriding this template to maintain our current functionality. Also, the static content generated in this menu is removed to avoid showing invalid links/data in case the AJAX fails for any reason. If this happen, the menu just won't show any information. --- .../doc_builder/templates/doc_builder/conf.py.tmpl | 9 +++++++++ readthedocs/templates/sphinx/versions.html | 12 ++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 readthedocs/templates/sphinx/versions.html diff --git a/readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl b/readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl index 2ad5b885cf1..761afda3097 100644 --- a/readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl +++ b/readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl @@ -132,6 +132,15 @@ if 'html_context' in globals(): else: html_context = context +# Add custom RTD templates +if using_rtd_theme: + if 'templates_path' in globals(): + templates_path.append('{{ template_path }}') + else: + templates_path = [ + '{{ template_path }}', + ] + # Add custom RTD extension if 'extensions' in globals(): # Insert at the beginning because it can interfere diff --git a/readthedocs/templates/sphinx/versions.html b/readthedocs/templates/sphinx/versions.html new file mode 100644 index 00000000000..9abecf29d62 --- /dev/null +++ b/readthedocs/templates/sphinx/versions.html @@ -0,0 +1,12 @@ +{# Template override to avoid adding static version menu into Read the Docs production sites #} +{# Add rst-badge after rst-versions for small badge style. #} +
+ + Read the Docs + v: {{ current_version }} + + +
+ {# This content is injected by an AJAX call to readthedocs.org/readthedocs.com #} +
+