/
version-compare.js
38 lines (30 loc) · 1.02 KB
/
version-compare.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const rtddata = require('./rtd-data');
const { createDomNode } = require('./utils');
function init(data) {
let rtd = rtddata.get();
/// Out of date message
if (data.is_highest) {
return;
}
let currentURL = window.location.pathname.replace(rtd['version'], data.slug);
let warning = createDomNode('div', {class: 'admonition warning'});
let link = createDomNode('a', {href: currentURL});
link.innerText = data.slug;
warning.innerHTML = '<p class="first admonition-title">Note</p> ' +
'<p class="last"> ' +
'You are not reading the most recent version of this documentation. ' +
link.outerHTML +
' is the latest version available.' +
'</p>';
let selectors = ['[role=main]', 'main', 'div.body', 'div.document'];
for (let selector of selectors) {
let element = document.querySelector(selector);
if (element !== null) {
element.prepend(warning);
break;
}
}
}
module.exports = {
init: init
};