From 966511474ca59aa44e5f67ad529e7be3df55c286 Mon Sep 17 00:00:00 2001 From: medmunds Date: Thu, 26 Jan 2017 13:55:53 -0800 Subject: [PATCH] Docs: show "unreleased" warning on latest version Fixes #52 --- docs/_static/version-alert.js | 30 ++++++++++++++++++++++++++++++ docs/_templates/layout.html | 3 +++ 2 files changed, 33 insertions(+) create mode 100644 docs/_static/version-alert.js create mode 100644 docs/_templates/layout.html diff --git a/docs/_static/version-alert.js b/docs/_static/version-alert.js new file mode 100644 index 0000000..7897c70 --- /dev/null +++ b/docs/_static/version-alert.js @@ -0,0 +1,30 @@ +"use strict"; + +// Similar to https://github.com/rtfd/readthedocs.org/blob/master/readthedocs/core/static-src/core/js/doc-embed/version-compare.js +// but adds admonition for the "latest" version -- which is (unreleased) master branch. + +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 = "

Note

" + + "

" + + "This document is for an unreleased development version. " + + "Documentation is available for the current stable release, " + + "or for older versions through the “v:” menu at bottom left." + + "

"; + warning.querySelector('a').href = window.location.pathname.replace('/latest', '/stable'); + + var parent = document.querySelector('div.body') + || document.querySelector('div.document') + || document.body; + parent.insertBefore(warning, parent.firstChild); +} + +document.addEventListener('DOMContentLoaded', warnOnLatestVersion); diff --git a/docs/_templates/layout.html b/docs/_templates/layout.html new file mode 100644 index 0000000..f2fec7e --- /dev/null +++ b/docs/_templates/layout.html @@ -0,0 +1,3 @@ +{% extends "!layout.html" %} + +{% set script_files = script_files + ["_static/version-alert.js"] %}