File tree Expand file tree Collapse file tree 4 files changed +32
-22
lines changed Expand file tree Collapse file tree 4 files changed +32
-22
lines changed Original file line number Diff line number Diff line change @@ -125,27 +125,24 @@ export default Controller.extend({
125
125
return data ;
126
126
} ) ,
127
127
128
+ readme : alias ( 'loadReadmeTask.last.value' ) ,
129
+
128
130
loadReadmeTask : task ( function * ( ) {
129
- if ( this . currentVersion . get ( 'readme_path' ) ) {
130
- try {
131
- let r = yield fetch ( this . currentVersion . get ( 'readme_path' ) ) ;
132
- if ( r . ok ) {
133
- this . crate . set ( 'readme' , yield r . text ( ) ) ;
134
-
135
- if ( typeof document !== 'undefined' ) {
136
- setTimeout ( ( ) => {
137
- let e = document . createEvent ( 'CustomEvent' ) ;
138
- e . initCustomEvent ( 'hashchange' , true , true ) ;
139
- window . dispatchEvent ( e ) ;
140
- } ) ;
141
- }
142
- } else {
143
- this . crate . set ( 'readme' , null ) ;
144
- }
145
- } catch ( error ) {
146
- this . crate . set ( 'readme' , null ) ;
147
- }
131
+ let version = this . currentVersion ;
132
+
133
+ let readme = version . loadReadmeTask . lastSuccessful
134
+ ? version . loadReadmeTask . lastSuccessful . value
135
+ : yield version . loadReadmeTask . perform ( ) ;
136
+
137
+ if ( typeof document !== 'undefined' ) {
138
+ setTimeout ( ( ) => {
139
+ let e = document . createEvent ( 'CustomEvent' ) ;
140
+ e . initCustomEvent ( 'hashchange' , true , true ) ;
141
+ window . dispatchEvent ( e ) ;
142
+ } ) ;
148
143
}
144
+
145
+ return readme ;
149
146
} ) ,
150
147
151
148
documentationLink : computed (
Original file line number Diff line number Diff line change @@ -39,4 +39,15 @@ export default Model.extend({
39
39
40
40
return { normal, build, dev } ;
41
41
} ) . keepLatest ( ) ,
42
+
43
+ loadReadmeTask : task ( function * ( ) {
44
+ if ( this . readme_path ) {
45
+ let response = yield fetch ( this . readme_path ) ;
46
+ if ( ! response . ok ) {
47
+ throw new Error ( `README request for ${ this . crateName } v${ this . num } failed` ) ;
48
+ }
49
+
50
+ return yield response . text ( ) ;
51
+ }
52
+ } ) . keepLatest ( ) ,
42
53
} ) ;
Original file line number Diff line number Diff line change @@ -62,7 +62,9 @@ export default Route.extend({
62
62
this . _super ( ...arguments ) ;
63
63
64
64
model . version . loadDepsTask . perform ( ) ;
65
- controller . loadReadmeTask . perform ( ) ;
65
+ controller . loadReadmeTask . perform ( ) . catch ( ( ) => {
66
+ // ignored
67
+ } ) ;
66
68
67
69
let { crate } = model ;
68
70
if ( ! crate . documentation || crate . documentation . startsWith ( 'https://docs.rs/' ) ) {
Original file line number Diff line number Diff line change 56
56
<CrateTomlCopy @copyText ={{ this.crateTomlText }} />
57
57
{{ /if }}
58
58
</div >
59
- {{ #if this.crate. readme }}
59
+ {{ #if this.readme }}
60
60
<section local-class =" crate-readme" aria-label =" Readme" {{ highlight-syntax selector =" pre > code" }} >
61
- {{ html-safe this.crate. readme }}
61
+ {{ html-safe this.readme }}
62
62
</section >
63
63
{{ else }}
64
64
{{ #if this.crate.description }}
You can’t perform that action at this time.
0 commit comments