Skip to content

Commit 9665114

Browse files
committed
Docs: show "unreleased" warning on latest version
Fixes #52
1 parent 9e64116 commit 9665114

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

docs/_static/version-alert.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"use strict";
2+
3+
// Similar to https://github.com/rtfd/readthedocs.org/blob/master/readthedocs/core/static-src/core/js/doc-embed/version-compare.js
4+
// but adds admonition for the "latest" version -- which is (unreleased) master branch.
5+
6+
function warnOnLatestVersion() {
7+
8+
// The warning text and link is really specific to RTD hosting,
9+
// so we can just check their global to determine version:
10+
if (!window.READTHEDOCS_DATA || window.READTHEDOCS_DATA.version !== "latest") {
11+
return; // not latest, or not on RTD
12+
}
13+
14+
var warning = document.createElement('div');
15+
warning.setAttribute('class', 'admonition danger');
16+
warning.innerHTML = "<p class='first admonition-title'>Note</p> " +
17+
"<p class='last'> " +
18+
"This document is for an <strong>unreleased development version</strong>. " +
19+
"Documentation is available for the <a href='/en/stable/'>current stable release</a>, " +
20+
"or for older versions through the &ldquo;v:&rdquo; menu at bottom left." +
21+
"</p>";
22+
warning.querySelector('a').href = window.location.pathname.replace('/latest', '/stable');
23+
24+
var parent = document.querySelector('div.body')
25+
|| document.querySelector('div.document')
26+
|| document.body;
27+
parent.insertBefore(warning, parent.firstChild);
28+
}
29+
30+
document.addEventListener('DOMContentLoaded', warnOnLatestVersion);

docs/_templates/layout.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{% extends "!layout.html" %}
2+
3+
{% set script_files = script_files + ["_static/version-alert.js"] %}

0 commit comments

Comments
 (0)