@@ -129,18 +129,48 @@ edition = "2021"
129129 let mut target_docs_path: Option < PathBuf > = None ;
130130 let mut found_count = 0 ;
131131
132+ // Convert crate name with hyphens to underscores for directory matching
133+ let expected_dir_name = crate_name. replace ( "-" , "_" ) ;
134+
132135 if base_doc_path. is_dir ( ) {
136+ eprintln ! ( "Looking for documentation in: {}" , base_doc_path. display( ) ) ;
137+ eprintln ! ( "Target crate directory name: {}" , expected_dir_name) ;
138+
133139 for entry_result in fs:: read_dir ( & base_doc_path) ? {
134140 let entry = entry_result?;
135141 if entry. file_type ( ) ?. is_dir ( ) {
136142 let dir_path = entry. path ( ) ;
143+ let dir_name = dir_path. file_name ( )
144+ . and_then ( |n| n. to_str ( ) )
145+ . unwrap_or ( "" ) ;
146+
147+ eprintln ! ( " Found directory: {}" , dir_name) ;
148+
149+ // Skip the temp crate's own documentation
150+ if dir_name == "temp_doc_crate" {
151+ eprintln ! ( " -> Skipping temp_doc_crate" ) ;
152+ continue ;
153+ }
154+
137155 let index_html_path = dir_path. join ( "index.html" ) ;
138156 if index_html_path. is_file ( ) {
139- if target_docs_path. is_none ( ) {
157+ eprintln ! ( " -> Has index.html" ) ;
158+
159+ // Prefer the directory that matches our target crate name
160+ if dir_name == expected_dir_name {
161+ eprintln ! ( " -> MATCHES target crate name!" ) ;
162+ target_docs_path = Some ( dir_path) ;
163+ found_count = 1 ; // Reset count since we found our target
164+ break ; // Stop searching, we found what we want
165+ } else if target_docs_path. is_none ( ) {
166+ // Keep as fallback if we don't find exact match
140167 target_docs_path = Some ( dir_path) ;
168+ found_count += 1 ;
169+ } else {
170+ found_count += 1 ;
141171 }
142- found_count += 1 ;
143172 } else {
173+ eprintln ! ( " -> No index.html" ) ;
144174 }
145175 }
146176 }
@@ -201,7 +231,7 @@ edition = "2021"
201231 }
202232 }
203233
204- // --- Initialize paths_to_process and explicitly add the root index.html if it exists ---
234+ // --- Initialize paths_to_process and explicitly add the root index.html if it exists ---
205235 let mut paths_to_process: Vec < PathBuf > = Vec :: new ( ) ;
206236 let root_index_path = docs_path. join ( "index.html" ) ;
207237 if root_index_path. is_file ( ) {
0 commit comments