Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions docs/sphinx/source/_static/version-alert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"use strict";

// Source:
// https://github.com/anymail/django-anymail/blob/4c443f5515d1d5269a95cb54cf75057c56a3b150/docs/_static/version-alert.js
// via:
// https://github.com/qucontrol/krotov/blob/969fc980346e6411903de854118c48c51208a810/docs/_static/version-alert.js
// following instructions here:
// https://michaelgoerz.net/notes/showing-a-warning-for-the-latest-documentation-on-readthedocs.html

function warnOnLatestVersion() {

// The warning text and link is really specific to RTD hosting,
// so we can just check their global to determine version:
if (!window.READTHEDOCS_DATA || window.READTHEDOCS_DATA.version !== "latest") {
return; // not latest, or not on RTD
}

var warning = document.createElement('div');
warning.setAttribute('class', 'admonition danger');
warning.innerHTML = "<p class='first admonition-title'>Note</p> " +
"<p class='last'> " +
"This document is for an <strong>unreleased development version</strong>. " +
"Documentation is available for the <a href='/en/stable/'>current stable release</a>, " +
"or for older versions through the &ldquo;v:&rdquo; menu at bottom left." +
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This text leaves the reader to infer that documentation for an "unreleased development version" may not be appropriate for their use case. Should we explicitly state this? Open to suggestions.

"</p>";
warning.querySelector('a').href = window.location.pathname.replace('/latest', '/stable');
Copy link
Member Author

@kandersolar kandersolar Nov 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is a bit heavy-handed in that it replaces any and all instances (not just the relevant instance) of /latest with /stable in the url. So if we someday have a page that happens to contain an unrelated "/latest" (e.g. /en/latest/auto_examples/latest_CEC_modules.html or something), it would blindly edit both instances. I guess an easy improvement is to replace /en/latest with /en/stable. I guess the most robust fix would include some semantic understanding of URL structure. Maybe this is much ado about something that will probably never happen.


var parent = document.querySelector('div.body')
|| document.querySelector('div.document')
|| document.body;
parent.insertBefore(warning, parent.firstChild);
}

document.addEventListener('DOMContentLoaded', warnOnLatestVersion);
2 changes: 2 additions & 0 deletions docs/sphinx/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ def setup(app):
# Override footnote callout CSS to be normal text instead of superscript
# In-line links to references as numbers in brackets.
app.add_css_file("reference_format.css")
# Add a warning banner at the top of the page if viewing the "latest" docs
app.add_javascript("version-alert.js")

# -- Options for LaTeX output ---------------------------------------------

Expand Down