Skip to content

Commit 8401e90

Browse files
aszenzcalebcartwright
authored andcommitted
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.
1 parent 93c2e65 commit 8401e90

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

docs/index.html

+22-11
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@
8282
const queryParams = new URLSearchParams(window.location.search);
8383
const searchParam = queryParams.get('search');
8484
const searchTerm = null !== searchParam ? searchParam : '';
85+
const versionParam = queryParams.get('version');
86+
const parseVersionParam = (version) => {
87+
if (version === 'master') return 'master';
88+
if (version.startsWith('v')) return version;
89+
return `v${version}`;
90+
};
91+
const versionNumber = null !== versionParam ? parseVersionParam(versionParam) : 'master';
8592
new Vue({
8693
el: '#app',
8794
data: {
@@ -90,7 +97,7 @@
9097
configurationDescriptions: [],
9198
searchCondition: searchTerm,
9299
shouldStable: false,
93-
version: 'master',
100+
version: versionNumber,
94101
oldVersion: undefined,
95102
versionOptions: ['master']
96103
},
@@ -99,16 +106,20 @@
99106
if (this.version !== this.oldVersion) {
100107
const ConfigurationMdUrl =
101108
`https://raw.githubusercontent.com/rust-lang/rustfmt/${this.version}/Configurations.md`;
102-
const res = await axios.get(ConfigurationMdUrl);
103-
const {
104-
about,
105-
configurationAbout,
106-
configurationDescriptions
107-
} = parseMarkdownAst(res.data);
108-
this.aboutHtml = marked.parser(about);
109-
this.configurationAboutHtml = marked.parser(configurationAbout);
110-
this.configurationDescriptions = configurationDescriptions;
111-
this.oldVersion = this.version;
109+
try {
110+
const res = await axios.get(ConfigurationMdUrl);
111+
const {
112+
about,
113+
configurationAbout,
114+
configurationDescriptions
115+
} = parseMarkdownAst(res.data);
116+
this.aboutHtml = marked.parser(about);
117+
this.configurationAboutHtml = marked.parser(configurationAbout);
118+
this.configurationDescriptions = configurationDescriptions;
119+
this.oldVersion = this.version;
120+
} catch(error) {
121+
this.aboutHtml = "<p>Failed to get configuration options for this version, please select the version from the dropdown above.</p>";
122+
}
112123
}
113124

114125
const ast = this.configurationDescriptions

0 commit comments

Comments
 (0)