From 61731057c0bf59194e7fcd12422820c4876cd781 Mon Sep 17 00:00:00 2001 From: asrar Date: Sat, 20 Jun 2020 23:55:24 +0530 Subject: [PATCH 1/3] Adds query param for version no This adds support for using a query parameter for selecting the version no --- docs/index.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/index.html b/docs/index.html index c89c73d4cf7..17e26ad6a92 100644 --- a/docs/index.html +++ b/docs/index.html @@ -82,6 +82,7 @@ const queryParams = new URLSearchParams(window.location.search); const searchParam = queryParams.get('search'); const searchTerm = null !== searchParam ? searchParam : ''; + const versionNumber = null !== queryParams.get('version') ? 'v' + queryParams.get('version') : 'master'; new Vue({ el: '#app', data: { @@ -90,7 +91,7 @@ configurationDescriptions: [], searchCondition: searchTerm, shouldStable: false, - version: 'master', + version: versionNumber, oldVersion: undefined, versionOptions: ['master'] }, From e6ea711cc51e6fc5770c5ee0e2cde5d0d8e5d4e3 Mon Sep 17 00:00:00 2001 From: asrar Date: Sun, 21 Jun 2020 11:05:32 +0530 Subject: [PATCH 2/3] 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. --- docs/index.html | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/docs/index.html b/docs/index.html index 17e26ad6a92..f369b3fc126 100644 --- a/docs/index.html +++ b/docs/index.html @@ -100,16 +100,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 = "

Failed to get configuration options for this version, please select the version from the dropdown above.

"; + } } const ast = this.configurationDescriptions From 837caaa700a3edb4bf0522ebb3bf4b9e1316ea52 Mon Sep 17 00:00:00 2001 From: asrar Date: Mon, 22 Jun 2020 21:45:51 +0530 Subject: [PATCH 3/3] Makes version selection better Covers a few common cases in which the version number can be specified. --- docs/index.html | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/index.html b/docs/index.html index f369b3fc126..c221c6db71f 100644 --- a/docs/index.html +++ b/docs/index.html @@ -82,7 +82,13 @@ const queryParams = new URLSearchParams(window.location.search); const searchParam = queryParams.get('search'); const searchTerm = null !== searchParam ? searchParam : ''; - const versionNumber = null !== queryParams.get('version') ? 'v' + queryParams.get('version') : 'master'; + 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: {