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
+
2
7
console . debug ( "injectVersionWarningBanner" ) ;
3
8
var current_url = window . location . pathname ;
4
9
var isIndex = current_url . endsWith ( running_version . slug + "/" ) || current_url . endsWith ( running_version . slug + "/index.html" ) ;
5
10
6
11
var others = [ ] ;
7
12
$ . each ( versions , function ( i , version ) {
8
13
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>" ) ;
14
15
}
15
16
} ) ;
16
17
let other = others . pop ( ) ;
@@ -19,29 +20,32 @@ function injectVersionWarningBanner(running_version, highest_version, config, ve
19
20
other = first + " & " + other ;
20
21
}
21
22
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
39
45
} 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
45
49
}
46
50
47
51
if ( msg ) {
@@ -51,8 +55,8 @@ function injectVersionWarningBanner(running_version, highest_version, config, ve
51
55
. replace ( "{id_div}" , config . banner . id_div )
52
56
. replace ( "{banner_title}" , title )
53
57
. 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 )
56
60
. replace ( "{other}" , other )
57
61
) ;
58
62
@@ -61,19 +65,19 @@ function injectVersionWarningBanner(running_version, highest_version, config, ve
61
65
}
62
66
}
63
67
64
- function getHighestVersion ( versions ) {
68
+ function getHighestVersion ( results ) {
65
69
console . debug ( "getHighestVersion" ) ;
66
70
var highest_version ;
67
71
68
- $ . each ( versions , function ( i , version ) {
69
- if ( isNaN ( version . slug ) ) {
72
+ $ . each ( results , function ( i , result ) {
73
+ if ( isNaN ( result . slug ) ) {
70
74
// Skip versions that are not numbers
71
75
}
72
76
else if ( ! highest_version ) {
73
- highest_version = version ;
77
+ highest_version = result ;
74
78
}
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 ;
77
81
}
78
82
} ) ;
79
83
return highest_version ;
@@ -82,8 +86,8 @@ function getHighestVersion(versions) {
82
86
83
87
function checkVersion ( config ) {
84
88
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 ) ;
87
91
88
92
var get_data = {
89
93
project__slug : config . project . slug ,
@@ -95,7 +99,7 @@ function checkVersion(config) {
95
99
// Access of API is broken by CORS
96
100
// https://readthedocs.org/api/v2/version/?project__slug=thunderbird-webextension-apis&active=true
97
101
//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" ,
99
103
// Used when working locally for development
100
104
// crossDomain: true,
101
105
// xhrFields: {
@@ -105,9 +109,8 @@ function checkVersion(config) {
105
109
data : get_data ,
106
110
success : function ( versions ) {
107
111
// 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" ] ) ;
111
114
} ,
112
115
error : function ( ) {
113
116
console . error ( "Error loading Read the Docs active versions." ) ;
@@ -125,6 +128,7 @@ function init() {
125
128
url : base_url + "../../_static/data/versionwarning-data.json" ,
126
129
success : function ( config ) {
127
130
// Check if there is already a banner added statically
131
+ console . debug ( { config} )
128
132
var banner = document . getElementById ( config . banner . id_div ) ;
129
133
if ( banner ) {
130
134
console . debug ( "There is already a banner added. No checking versions." )
0 commit comments