about summary refs log tree commit diff
path: root/docs
diff options
context:
space:
mode:
authorasrar <aszenz@gmail.com>2020-06-24 05:12:40 +0530
committerCaleb Cartwright <calebcartwright@users.noreply.github.com>2021-08-17 21:55:26 -0500
commit31c97ce0f067ddf5c01217cf172ef1ff260ca564 (patch)
treed7ce585acebb59d529f34e14ffc07f8f615006a1 /docs
parentc5f1d9698e83fbbf59c97aa229804274daf4cc8c (diff)
downloadrust-31c97ce0f067ddf5c01217cf172ef1ff260ca564.tar.gz
rust-31c97ce0f067ddf5c01217cf172ef1ff260ca564.zip
Adds query param for version no (#4270)
* Adds query param for version no

This adds support for using a query parameter for selecting the version no

* Adds error handling to configuration request

Catch request exception in case fetching the configuration from the url fails, this can happen either if non existent version number is passed in or because of server issues.

* Makes version selection better

Covers a few common cases in which the version number can be specified.
Diffstat (limited to 'docs')
-rw-r--r--docs/index.html33
1 files changed, 22 insertions, 11 deletions
diff --git a/docs/index.html b/docs/index.html
index c89c73d4cf7..c221c6db71f 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -82,6 +82,13 @@
             const queryParams = new URLSearchParams(window.location.search);
             const searchParam = queryParams.get('search');
             const searchTerm = null !== searchParam ? searchParam : '';
+            const versionParam = queryParams.get('version');
+            const parseVersionParam = (version) => {
+              if (version === 'master') return 'master';
+              if (version.startsWith('v')) return version;
+              return `v${version}`;
+            };
+            const versionNumber = null !== versionParam ? parseVersionParam(versionParam) : 'master';
             new Vue({
               el: '#app',
               data: {
@@ -90,7 +97,7 @@
                 configurationDescriptions: [],
                 searchCondition: searchTerm,
                 shouldStable: false,
-                version: 'master',
+                version: versionNumber,
                 oldVersion: undefined,
                 versionOptions: ['master']
               },
@@ -99,16 +106,20 @@
                   if (this.version !== this.oldVersion) {
                     const ConfigurationMdUrl =
                       `https://raw.githubusercontent.com/rust-lang/rustfmt/${this.version}/Configurations.md`;
-                    const res = await axios.get(ConfigurationMdUrl);
-                    const {
-                      about,
-                      configurationAbout,
-                      configurationDescriptions
-                    } = parseMarkdownAst(res.data);
-                    this.aboutHtml = marked.parser(about);
-                    this.configurationAboutHtml = marked.parser(configurationAbout);
-                    this.configurationDescriptions = configurationDescriptions;
-                    this.oldVersion = this.version;
+                    try {
+                      const res = await axios.get(ConfigurationMdUrl);
+                      const {
+                        about,
+                        configurationAbout,
+                        configurationDescriptions
+                      } = parseMarkdownAst(res.data);
+                      this.aboutHtml = marked.parser(about);
+                      this.configurationAboutHtml = marked.parser(configurationAbout);
+                      this.configurationDescriptions = configurationDescriptions;
+                      this.oldVersion = this.version;
+                    } catch(error) {
+                        this.aboutHtml = "<p>Failed to get configuration options for this version, please select the version from the dropdown above.</p>";
+                    }
                   }
 
                   const ast = this.configurationDescriptions