File tree Expand file tree Collapse file tree 4 files changed +25
-22
lines changed Expand file tree Collapse file tree 4 files changed +25
-22
lines changed Original file line number Diff line number Diff line change @@ -140,10 +140,9 @@ async fn render<'a>(
140
140
. to_str ( )
141
141
. expect ( "path must convert to a string" )
142
142
. to_string ( ) ;
143
- let mut url = path. clone ( ) ;
143
+ let url = path. clone ( ) ;
144
144
if path. ends_with ( "/" ) {
145
145
path. push_str ( "README" ) ;
146
- url. push_str ( "./" ) ;
147
146
}
148
147
149
148
// Get the document content
@@ -153,8 +152,14 @@ async fn render<'a>(
153
152
154
153
// Read to string
155
154
let contents = match tokio:: fs:: read_to_string ( & path) . await {
156
- Ok ( contents) => contents,
157
- Err ( _) => return Err ( Status :: NotFound ) ,
155
+ Ok ( contents) => {
156
+ info ! ( "loading markdown file: '{:?}" , path) ;
157
+ contents
158
+ }
159
+ Err ( err) => {
160
+ warn ! ( "Error parsing markdown file: '{:?}' {:?}" , path, err) ;
161
+ return Err ( Status :: NotFound ) ;
162
+ }
158
163
} ;
159
164
let parts = contents. split ( "---" ) . collect :: < Vec < & str > > ( ) ;
160
165
let ( ( image, description) , contents) = if parts. len ( ) > 1 {
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ pub struct NavLink {
12
12
pub href : String ,
13
13
pub children : Vec < NavLink > ,
14
14
pub open : bool ,
15
+ pub active : bool ,
15
16
}
16
17
17
18
impl NavLink {
@@ -23,6 +24,7 @@ impl NavLink {
23
24
href : "#" . to_owned ( ) ,
24
25
children : vec ! [ ] ,
25
26
open : false ,
27
+ active : false ,
26
28
}
27
29
}
28
30
@@ -42,20 +44,14 @@ impl NavLink {
42
44
/// Automatically expand the link and it's parents
43
45
/// when one of the children is visible.
44
46
pub fn should_open ( & mut self , path : & str ) -> bool {
45
- self . open = self . href . contains ( & path) ;
46
- let open = if self . children . is_empty ( ) {
47
- self . open
48
- } else {
49
- for child in self . children . iter_mut ( ) {
50
- if child. should_open ( path) {
51
- self . open = true ;
52
- }
47
+ self . active = self . href . ends_with ( & path) ;
48
+ self . open = self . active ;
49
+ for child in self . children . iter_mut ( ) {
50
+ if child. should_open ( path) {
51
+ self . open = true ;
53
52
}
54
-
55
- self . open
56
- } ;
57
-
58
- open
53
+ }
54
+ self . open
59
55
}
60
56
}
61
57
Original file line number Diff line number Diff line change @@ -572,11 +572,12 @@ pub fn get_sub_links(list: &markdown::mdast::List) -> Result<Vec<NavLink>> {
572
572
for node in link. children . iter ( ) {
573
573
match node {
574
574
markdown:: mdast:: Node :: Text ( text) => {
575
- let mut url =
576
- Path :: new ( & link. url ) . with_extension ( "" ) ;
575
+ let mut url = Path :: new ( & link. url )
576
+ . with_extension ( "" )
577
+ . to_string_lossy ( )
578
+ . to_string ( ) ;
577
579
if url. ends_with ( "README" ) {
578
- url =
579
- url. parent ( ) . unwrap ( ) . join ( "./" ) . into ( ) ;
580
+ url = url. replace ( "README" , "" ) ;
580
581
}
581
582
let url = Path :: new ( "/docs/guides" )
582
583
. join ( url)
Original file line number Diff line number Diff line change 1
1
< div class ="nav flex-column " role ="tablist " aria-orientation ="vertical ">
2
2
< %
3
- let color = if open {
3
+
4
+ let color = if active {
4
5
"purple"
5
6
} else {
6
7
""
You can’t perform that action at this time.
0 commit comments