Docs: show "unreleased" warning on latest version

Fixes #52
This commit is contained in:
medmunds
2017-01-26 13:55:53 -08:00
parent 9e641169e3
commit 966511474c
2 changed files with 33 additions and 0 deletions

30
docs/_static/version-alert.js vendored Normal file
View File

@@ -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 = "<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." +
"</p>";
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);

3
docs/_templates/layout.html vendored Normal file
View File

@@ -0,0 +1,3 @@
{% extends "!layout.html" %}
{% set script_files = script_files + ["_static/version-alert.js"] %}