Skip to content

Commit

Permalink
Adds query param for version no (rust-lang#4270)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
aszenz authored and calebcartwright committed Aug 18, 2021
1 parent c5f1d96 commit 31c97ce
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -90,7 +97,7 @@
configurationDescriptions: [],
searchCondition: searchTerm,
shouldStable: false,
version: 'master',
version: versionNumber,
oldVersion: undefined,
versionOptions: ['master']
},
Expand All @@ -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
Expand Down

0 comments on commit 31c97ce

Please sign in to comment.