Skip to content

Commit 0fdae21

Browse files
committed
test
1 parent 802a5ee commit 0fdae21

File tree

5 files changed

+85
-98
lines changed

5 files changed

+85
-98
lines changed

_extensions/versionwarning/_static/js/versionwarning.js

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
function injectVersionWarningBanner(running_version, highest_version, config, versions) {
1+
function injectVersionWarningBanner(running_version_slug, config, versions) {
2+
const running_version = versions.find(e => e.slug == running_version_slug);
3+
const highest_version = getHighestVersion(
4+
versions.filter(e => e.manifest_version == running_version.manifest_version)
5+
);
6+
27
console.debug("injectVersionWarningBanner");
38
var current_url = window.location.pathname;
49
var isIndex = current_url.endsWith(running_version.slug + "/") || current_url.endsWith(running_version.slug + "/index.html");
510

611
var others = [];
712
$.each(versions, function (i, version) {
813
if (version.slug != running_version.slug && version.slug != highest_version.slug) {
9-
let label = version.slug;
10-
if (label.startsWith("latest")) {
11-
label = "Latest"
12-
}
13-
others.push("<a href='" + current_url.replace(running_version.slug, version.slug) + "'>" + label + "</a>");
14+
others.push("<a href='" + current_url.replace(running_version.slug, version.slug) + "'>" + version.title + "</a>");
1415
}
1516
});
1617
let other = others.pop();
@@ -19,29 +20,32 @@ function injectVersionWarningBanner(running_version, highest_version, config, ve
1920
other = first + " & " + other;
2021
}
2122

22-
let msg = (config.banner.older_indexmessage && isIndex)
23-
? config.banner.older_indexmessage
24-
: config.banner.older_message;
25-
let title = config.banner.older_title;
26-
let type = config.banner.older_type
27-
if (running_version.slug == "latest-mv3") {
28-
msg = (config.banner.latest_mv3_indexmessage && isIndex)
29-
? config.banner.latest_mv3_indexmessage
30-
: config.banner.latest_mv3_message;
31-
title = config.banner.latest_mv3_title;
32-
type = config.banner.latest_mv3_type
33-
} else if (running_version.slug.startsWith("latest")) {
34-
msg = (config.banner.latest_indexmessage && isIndex)
35-
? config.banner.latest_indexmessage
36-
: config.banner.latest_message;
37-
title = config.banner.latest_title;
38-
type = config.banner.latest_type
23+
// Strings
24+
const versionwarning_latest_type = 'warning'
25+
const versionwarning_latest_title = 'Warning'
26+
const versionwarning_latest_message = 'This is the documentation for Thunderbird {this}. See version {newest} for the current ESR of Thunderbird.'
27+
28+
const versionwarning_current_type = 'note'
29+
const versionwarning_current_title = 'Note'
30+
const versionwarning_current_message = 'This is the documentation for Thunderbird ESR {this}. Other available versions are: {other}'
31+
32+
const versionwarning_older_type = 'warning'
33+
const versionwarning_older_title = 'Warning'
34+
const versionwarning_older_message = 'This is an outdated documentation for Thunderbird {this}. See version {newest} for the current ESR of Thunderbird.'
35+
36+
37+
let msg = versionwarning_older_message;
38+
let title = versionwarning_older_title;
39+
let type = versionwarning_older_type
40+
41+
if (running_version.slug.startsWith("latest") || running_version.slug.startsWith("beta")) {
42+
msg = versionwarning_latest_message;
43+
title = versionwarning_latest_title;
44+
type = versionwarning_latest_type
3945
} else if (running_version.slug == "stable" || running_version.slug == highest_version.slug) {
40-
msg = (config.banner.current_indexmessage && isIndex)
41-
? config.banner.current_indexmessage
42-
: config.banner.current_message;
43-
title = config.banner.current_title;
44-
type = config.banner.current_type
46+
msg = isIndex ? versionwarning_current_message : "";
47+
title = versionwarning_current_title;
48+
type = versionwarning_current_type
4549
}
4650

4751
if (msg) {
@@ -51,8 +55,8 @@ function injectVersionWarningBanner(running_version, highest_version, config, ve
5155
.replace("{id_div}", config.banner.id_div)
5256
.replace("{banner_title}", title)
5357
.replace("{admonition_type}", type)
54-
.replace("{newest}", '<a href="' + current_url.replace(running_version.slug, highest_version.slug) + '">' + highest_version.slug + '</a>')
55-
.replace("{this}", running_version.slug)
58+
.replace("{newest}", '<a href="' + current_url.replace(running_version.slug, highest_version.slug) + '">' + highest_version.title + '</a>')
59+
.replace("{this}", running_version.title)
5660
.replace("{other}", other)
5761
);
5862

@@ -61,19 +65,19 @@ function injectVersionWarningBanner(running_version, highest_version, config, ve
6165
}
6266
}
6367

64-
function getHighestVersion(versions) {
68+
function getHighestVersion(results) {
6569
console.debug("getHighestVersion");
6670
var highest_version;
6771

68-
$.each(versions, function (i, version) {
69-
if (isNaN(version.slug)) {
72+
$.each(results, function (i, result) {
73+
if (isNaN(result.slug)) {
7074
// Skip versions that are not numbers
7175
}
7276
else if (!highest_version) {
73-
highest_version = version;
77+
highest_version = result;
7478
}
75-
else if (parseInt(version.slug, 10) > parseInt(highest_version.slug, 10)) {
76-
highest_version = version;
79+
else if (result.version > highest_version.version) {
80+
highest_version = result;
7781
}
7882
});
7983
return highest_version;
@@ -82,8 +86,8 @@ function getHighestVersion(versions) {
8286

8387
function checkVersion(config) {
8488
console.debug("checkVersion");
85-
var running_version = config.version;
86-
console.debug("Running version: " + running_version.slug);
89+
var running_version_slug = config.version.slug;
90+
console.debug("Running version slug: " + running_version_slug);
8791

8892
var get_data = {
8993
project__slug: config.project.slug,
@@ -95,7 +99,7 @@ function checkVersion(config) {
9599
// Access of API is broken by CORS
96100
// https://readthedocs.org/api/v2/version/?project__slug=thunderbird-webextension-apis&active=true
97101
//url: config.meta.api_url + "version/",
98-
url: "https://webextension-api.thunderbird.net/en/stable/_static/versions.json",
102+
url: "https://webextension-api.thunderbird.net/en/latest/_static/versions.json",
99103
// Used when working locally for development
100104
// crossDomain: true,
101105
// xhrFields: {
@@ -105,9 +109,8 @@ function checkVersion(config) {
105109
data: get_data,
106110
success: function (versions) {
107111
// TODO: fetch more versions if there are more pages (next)
108-
highest_version = getHighestVersion(versions["results"]);
109-
console.debug("Highest version: " + highest_version.slug);
110-
injectVersionWarningBanner(running_version, highest_version, config, versions["results"]);
112+
console.debug({running_version_slug, config, versions})
113+
injectVersionWarningBanner(running_version_slug, config, versions["results"]);
111114
},
112115
error: function () {
113116
console.error("Error loading Read the Docs active versions.");
@@ -125,6 +128,7 @@ function init() {
125128
url: base_url + "../../_static/data/versionwarning-data.json",
126129
success: function (config) {
127130
// Check if there is already a banner added statically
131+
console.debug({config})
128132
var banner = document.getElementById(config.banner.id_div);
129133
if (banner) {
130134
console.debug("There is already a banner added. No checking versions.")

_extensions/versionwarning/extension.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,6 @@ def setup(app):
1616
</p>
1717
</div>'''
1818

19-
app.add_config_value('versionwarning_older_message', default_message, 'html')
20-
app.add_config_value('versionwarning_older_indexmessage', '', 'html')
21-
app.add_config_value('versionwarning_older_title', 'Warning', 'html')
22-
app.add_config_value('versionwarning_older_type', 'warning', 'html')
23-
24-
app.add_config_value('versionwarning_current_message', '', 'html')
25-
app.add_config_value('versionwarning_current_indexmessage', '', 'html')
26-
app.add_config_value('versionwarning_current_title', 'Warning', 'html')
27-
app.add_config_value('versionwarning_current_type', 'warning', 'html')
28-
29-
app.add_config_value('versionwarning_latest_message', '', 'html')
30-
app.add_config_value('versionwarning_latest_indexmessage', '', 'html')
31-
app.add_config_value('versionwarning_latest_title', 'Warning', 'html')
32-
app.add_config_value('versionwarning_latest_type', 'warning', 'html')
33-
34-
app.add_config_value('versionwarning_latest_mv3_message', '', 'html')
35-
app.add_config_value('versionwarning_latest_mv3_indexmessage', '', 'html')
36-
app.add_config_value('versionwarning_latest_mv3_title', 'Warning', 'html')
37-
app.add_config_value('versionwarning_latest_mv3_type', 'danger', 'html')
38-
3919
app.add_config_value('versionwarning_api_url', 'https://readthedocs.org/api/v2/', 'html')
4020
app.add_config_value('versionwarning_banner_html', banner_html, 'html')
4121
app.add_config_value('versionwarning_banner_id_div', 'version-warning-banner', 'html')

_extensions/versionwarning/signals.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,6 @@ def generate_versionwarning_data_json(app, config=None, **kwargs):
5151
'html': config.versionwarning_banner_html,
5252
'id_div': config.versionwarning_banner_id_div,
5353
'body_selector': config.versionwarning_body_selector,
54-
'older_message': config.versionwarning_older_message,
55-
'older_indexmessage': config.versionwarning_older_indexmessage,
56-
'older_title': config.versionwarning_older_title,
57-
'older_type': config.versionwarning_older_type,
58-
'current_message': config.versionwarning_current_message,
59-
'current_indexmessage': config.versionwarning_current_indexmessage,
60-
'current_title': config.versionwarning_current_title,
61-
'current_type': config.versionwarning_current_type,
62-
'latest_message': config.versionwarning_latest_message,
63-
'latest_indexmessage': config.versionwarning_latest_indexmessage,
64-
'latest_title': config.versionwarning_latest_title,
65-
'latest_type': config.versionwarning_latest_type,
66-
'latest_mv3_message': config.versionwarning_latest_mv3_message,
67-
'latest_mv3_indexmessage': config.versionwarning_latest_mv3_indexmessage,
68-
'latest_mv3_title': config.versionwarning_latest_mv3_title,
69-
'latest_mv3_type': config.versionwarning_latest_mv3_type,
7054
},
7155
'project': {
7256
'slug': config.versionwarning_project_slug,

_static/versions.json

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,51 @@
11
{
22
"results": [
33
{
4-
"slug": "91"
4+
"slug": "latest",
5+
"title": "Beta (Manifest V3)",
6+
"version": 0
57
},
68
{
7-
"slug": "102"
9+
"slug": "beta-mv2",
10+
"title": "Beta (Manifest V2)",
11+
"manifest_version": 2,
12+
"version": 0
813
},
914
{
10-
"slug": "115"
15+
"slug": "beta-mv3",
16+
"title": "Beta (Manifest V3)",
17+
"manifest_version": 3,
18+
"version": 0
1119
},
1220
{
13-
"slug": "latest"
21+
"slug": "91",
22+
"title": "91",
23+
"manifest_version": 2,
24+
"version": 91
25+
},
26+
{
27+
"slug": "102",
28+
"title": "102",
29+
"manifest_version": 2,
30+
"version": 102
31+
},
32+
{
33+
"slug": "115",
34+
"title": "115",
35+
"manifest_version": 2,
36+
"version": 115
37+
},
38+
{
39+
"slug": "128-esr-mv2",
40+
"title": "128 (Manifest V2)",
41+
"manifest_version": 2,
42+
"version": 128
43+
},
44+
{
45+
"slug": "128-esr-mv3",
46+
"title": "128 (Manifest V3)",
47+
"manifest_version": 3,
48+
"version": 128
1449
}
1550
]
1651
}

conf.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,6 @@
4343
# Configure headers
4444
versionwarning_body_selector = 'div[itemprop="articleBody"] h1'
4545

46-
versionwarning_latest_type = 'warning'
47-
versionwarning_latest_title = 'Warning'
48-
versionwarning_latest_message = 'This is the documentation for Thunderbird Beta (Manifest Version 2). See version {newest} for the current ESR of Thunderbird.'
49-
50-
versionwarning_latest_mv3_type = 'danger'
51-
versionwarning_latest_mv3_title = 'Warning (Manifest V3)'
52-
versionwarning_latest_message = 'This is the documentation for Thunderbird Beta (Manifest Version 3). See version {newest} for the current ESR of Thunderbird.'
53-
54-
versionwarning_current_type = 'note'
55-
versionwarning_current_title = 'Note'
56-
versionwarning_current_indexmessage = 'This is the documentation for the current ESR of Thunderbird, version {newest}. Other available versions are: {other}'
57-
58-
versionwarning_older_type = 'warning'
59-
versionwarning_older_title = 'Warning'
60-
versionwarning_older_message = 'This is an outdated documentation for Thunderbird {this}. See version {newest} for the current ESR of Thunderbird.'
61-
6246
def setup(app):
6347
app.add_js_file("custom.js")
6448
app.add_css_file('theme_overrides.css')

0 commit comments

Comments
 (0)