|
1 |
| -const CURRENT_VERSION = "/* VERSION TO BE REPLACED */"; |
| 1 | +(function() { |
| 2 | + |
| 3 | +let CURRENT_VERSION = -1; |
| 4 | + |
| 5 | +function get_current_version() { |
| 6 | + if (CURRENT_VERSION !== -1) { |
| 7 | + return CURRENT_VERSION; |
| 8 | + } |
| 9 | + const now = Date.now(); |
| 10 | + // Month is 0-indexed. |
| 11 | + // First release of Rust, 15 may 2015. |
| 12 | + const first_release = new Date(2015, 4, 15); |
| 13 | + const diff_time = Math.abs(now - first_release); |
| 14 | + const nb_days = Math.ceil(diff_time / (1000 * 60 * 60 * 24)); |
| 15 | + const nb_weeks = nb_days / 7; |
| 16 | + CURRENT_VERSION = Math.floor(nb_weeks / 6); |
| 17 | + return CURRENT_VERSION; |
| 18 | +} |
2 | 19 |
|
3 | 20 | function checkIfIsOldVersion() {
|
4 | 21 | if (["http:", "https:"].indexOf(window.location.protocol) === -1) {
|
@@ -159,12 +176,9 @@ function showSwitcher(isOldVersion) {
|
159 | 176 | version_picker.appendChild(createOption("beta", current_doc_version === "beta"));
|
160 | 177 | version_picker.appendChild(createOption("nightly", current_doc_version === "nightly"));
|
161 | 178 |
|
162 |
| - const version_parts = CURRENT_VERSION.split("."); |
163 |
| - for (let major = parseInt(version_parts[0]); major >= 1; --major) { |
164 |
| - for (let medium = parseInt(version_parts[1]); medium >= 0; --medium) { |
165 |
| - const version = `${major}.${medium}.0`; |
166 |
| - version_picker.appendChild(createOption(version, version === current_doc_version)); |
167 |
| - } |
| 179 | + for (let medium = get_current_version(); medium >= 0; --medium) { |
| 180 | + const version = `1.${medium}.0`; |
| 181 | + version_picker.appendChild(createOption(version, version === current_doc_version)); |
168 | 182 | }
|
169 | 183 |
|
170 | 184 | version_picker.style.color = "#000";
|
@@ -208,3 +222,5 @@ function showSwitcher(isOldVersion) {
|
208 | 222 | }
|
209 | 223 |
|
210 | 224 | showSwitcher(checkIfIsOldVersion());
|
| 225 | + |
| 226 | +}()); |
0 commit comments