@@ -8,7 +8,6 @@ export default Ember.Route.extend({
8
8
9
9
model ( params ) {
10
10
const requestedVersion = params . version_num === 'all' ? '' : params . version_num ;
11
-
12
11
const crate = this . modelFor ( 'crate' ) ;
13
12
const controller = this . controllerFor ( this . routeName ) ;
14
13
const maxVersion = crate . get ( 'max_version' ) ;
@@ -35,6 +34,20 @@ export default Ember.Route.extend({
35
34
return result ;
36
35
} ;
37
36
37
+ const fetchCrateDocumentation = ( ) => {
38
+ if ( ! crate . get ( 'documentation' ) ||
39
+ crate . get ( 'documentation' ) . substr ( 0 , 16 ) === 'https://docs.rs/' ) {
40
+ let crateName = crate . get ( 'name' ) ;
41
+ let crateVersion = params . version_num ;
42
+ ajax ( `https://docs.rs/crate/${ crateName } /${ crateVersion } /builds.json` )
43
+ . then ( ( r ) => {
44
+ if ( r . length > 0 && r [ 0 ] . build_status === true ) {
45
+ crate . set ( 'documentation' , `https://docs.rs/${ crateName } /${ crateVersion } /` ) ;
46
+ }
47
+ } ) ;
48
+ }
49
+ } ;
50
+
38
51
// Fallback to the crate's last stable version
39
52
// If `max_version` is `0.0.0` then all versions have been yanked
40
53
if ( ! requestedVersion && maxVersion !== '0.0.0' ) {
@@ -52,10 +65,13 @@ export default Ember.Route.extend({
52
65
} else {
53
66
params . version_num = latestStableVersion . get ( 'num' ) ;
54
67
}
55
- } ) ;
68
+ } ) . then ( fetchCrateDocumentation ) ;
56
69
} else {
57
70
params . version_num = maxVersion ;
71
+ fetchCrateDocumentation ( ) ;
58
72
}
73
+ } else {
74
+ fetchCrateDocumentation ( ) ;
59
75
}
60
76
61
77
controller . set ( 'crate' , crate ) ;
0 commit comments