Skip to content

Commit

Permalink
Maintenance: Introduce version warning for deprecated documentation
Browse files Browse the repository at this point in the history
This commit introduces a warning on all pages in case the page is not hosted on readthedocs.io from `master` branch. This allows us to introduce versioned documentations and also to spot possible pre-releases better.
  • Loading branch information
MrGeneration committed May 20, 2021
1 parent 2e30071 commit 678e179
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 11 deletions.
61 changes: 50 additions & 11 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
source_suffix = '.rst'
master_doc = 'index'
exclude_patterns = ['_build', 'html', 'doctrees']
extensions = ['versionwarning.extension']

locale_dirs = ['locale/']
gettext_compact = False
Expand All @@ -23,15 +24,53 @@

on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
if not on_rtd: # only import and set the theme if we're building docs locally
# Override default css to solve issues (e.g. width, overflows)
def setup(app):
app.add_css_file('theme/theme_overrides.css')
# Override default css to solve issues (e.g. width, overflows)
def setup(app):
app.add_css_file('theme/theme_overrides.css')

# We're running outside of readthedocs and expect the compiled version to
# be a pre release
branch = 'pre-release'

else:
# Override default css to solve issues (e.g. width, overflows)
html_context = {
'css_files': [
'https://media.readthedocs.org/css/sphinx_rtd_theme.css',
'https://media.readthedocs.org/css/readthedocs-doc-embed.css',
'_static/theme/theme_overrides.css'
],
}
# Override default css to solve issues (e.g. width, overflows)
html_context = {
'css_files': [
'https://media.readthedocs.org/css/sphinx_rtd_theme.css',
'https://media.readthedocs.org/css/readthedocs-doc-embed.css',
'_static/theme/theme_overrides.css'
],
}

# Get current version we're on for possible version warning
version = os.environ.get('READTHEDOCS_VERSION')

# If we're **not on latest**, we'll display a deprecation warning.
if version == 'latest':
branch = version
else:
branch = "old-version"

# Default definitions for this documentations version warnings if applicable
# https://sphinx-version-warning.readthedocs.io/en/latest/configuration.html
versionwarning_project_slug = "zammad-admin-documentation"
versionwarning_admonition_type = "warning"
versionwarning_project_version = branch
versionwarning_body_selector = "div.document"

versionwarning_messages = {
"pre-release": (
"You're viewing a <strong>pre-release</strong> version of this "
"documentation! If you want to see the stable, current version of "
"this documentation, please see "
'<a href="https://user-docs.zammad.org/en/latest/" '
'title="current documentation version">here</a>.'
),
"old-version": (
"You're viewing a <strong>deprecated</strong> version of Zammads "
"documentation. If you're still running that version, please consider "
'<a href="https://docs.zammad.org/en/latest/install/update.html" '
'title="Updating Zammad">Updating Zammad</a> asap.'
"If you're a hosted user, please contact support."
),
}
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sphinx-version-warning

0 comments on commit 678e179

Please sign in to comment.