@@ -15,21 +15,52 @@ define([
15
15
this . notebook_list = notebook_list ;
16
16
this . base_url = options . base_url || utils . get_body_data ( "baseUrl" ) ;
17
17
this . contents = options . contents ;
18
+ this . drawn_readme = null ;
18
19
19
20
this . init_readme ( ) ;
20
21
this . bind_events ( ) ;
21
22
} ;
22
23
24
+ DirectoryReadme . prototype . find_readme = function ( ) {
25
+ var files_in_directory = this . notebook_list . model_list . content ;
26
+ for ( var i = 0 ; i < files_in_directory . length ; i ++ ) {
27
+ var file = files_in_directory [ i ] ;
28
+ if ( file . type === "file"
29
+ && file . mimetype === "text/markdown"
30
+ && file . name . toLowerCase ( ) . split ( "." ) [ 0 ] === "readme" ) {
31
+ return file ;
32
+ }
33
+ }
34
+ return null ;
35
+ }
36
+
37
+ DirectoryReadme . prototype . needs_update = function ( readme ) {
38
+ if ( this . drawn_readme === readme ) return false ;
39
+ if ( this . drawn_readme === null || readme === null ) return true ;
40
+ if ( this . drawn_readme . path !== readme . path ) return true ;
41
+ if ( this . draw_readme . last_modified < readme . last_modified ) return true ;
42
+ return false ;
43
+ }
44
+
45
+
23
46
DirectoryReadme . prototype . fetch_readme = function ( ) {
24
- var that = this ;
25
- this . contents . get ( utils . url_path_join ( this . notebook_list . notebook_path , 'readme.md' ) , { type : 'file' } ) . then (
26
- function ( file ) {
27
- that . draw_readme ( file ) ;
28
- } ,
29
- function ( ) {
30
- that . clear_readme ( ) ;
47
+ var readme = this . find_readme ( ) ;
48
+
49
+ if ( this . needs_update ( readme ) ) {
50
+ if ( readme === null ) {
51
+ this . clear_readme ( ) ;
52
+ } else {
53
+ var that = this ;
54
+ this . contents . get ( readme . path , { type : 'file' } ) . then (
55
+ function ( file ) {
56
+ that . draw_readme ( file ) ;
57
+ } ,
58
+ function ( ) {
59
+ that . clear_readme ( ) ;
60
+ }
61
+ ) ;
31
62
}
32
- ) ;
63
+ }
33
64
}
34
65
35
66
DirectoryReadme . prototype . bind_events = function ( ) {
@@ -71,10 +102,12 @@ define([
71
102
}
72
103
73
104
DirectoryReadme . prototype . clear_readme = function ( ) {
105
+ this . drawn_readme = null ;
74
106
this . element . hide ( ) ;
75
107
}
76
108
77
109
DirectoryReadme . prototype . draw_readme = function ( file ) {
110
+ this . drawn_readme = file ;
78
111
this . element . show ( ) ;
79
112
this . title
80
113
. attr ( "href" ,
0 commit comments