|
82 | 82 | const queryParams = new URLSearchParams(window.location.search);
|
83 | 83 | const searchParam = queryParams.get('search');
|
84 | 84 | 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'; |
85 | 92 | new Vue({
|
86 | 93 | el: '#app',
|
87 | 94 | data: {
|
|
90 | 97 | configurationDescriptions: [],
|
91 | 98 | searchCondition: searchTerm,
|
92 | 99 | shouldStable: false,
|
93 |
| - version: 'master', |
| 100 | + version: versionNumber, |
94 | 101 | oldVersion: undefined,
|
95 | 102 | versionOptions: ['master']
|
96 | 103 | },
|
|
99 | 106 | if (this.version !== this.oldVersion) {
|
100 | 107 | const ConfigurationMdUrl =
|
101 | 108 | `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 | + } |
112 | 123 | }
|
113 | 124 |
|
114 | 125 | const ast = this.configurationDescriptions
|
|
0 commit comments