Skip to content

Commit 3c2793d

Browse files
committed
Show the last stable release of a crate on it's index page
— Elliot Jackson <elliot@elliotekj.com>
1 parent 94c9d54 commit 3c2793d

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

app/routes/crate/version.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,34 @@ export default Ember.Route.extend({
1010
const controller = this.controllerFor(this.routeName);
1111
const maxVersion = crate.get('max_version');
1212

13-
// Fall back to the crate's `max_version` property
13+
const isUnstableVersion = (version) => {
14+
const unstableFlags = ['alpha', 'beta'];
15+
16+
return unstableFlags.some((flag) => {
17+
return version.includes(flag);
18+
});
19+
};
20+
21+
// Fallback to the crate's last stable version
1422
if (!requestedVersion) {
15-
params.version_num = maxVersion;
23+
if (isUnstableVersion(maxVersion)) {
24+
crate.get('versions').then(versions => {
25+
const latestStableVersion = versions.find(version => {
26+
if (!isUnstableVersion(version.get('num'))) {
27+
return version;
28+
}
29+
});
30+
31+
if (latestStableVersion == null) {
32+
// If no stable version exists, fallback to `maxVersion`
33+
params.version_num = maxVersion;
34+
} else {
35+
params.version_num = latestStableVersion.get('num');
36+
}
37+
});
38+
} else {
39+
params.version_num = maxVersion;
40+
}
1641
}
1742

1843
controller.set('crate', crate);

0 commit comments

Comments
 (0)