@@ -192,6 +192,7 @@ pub struct Book {
192192
193193impl Book {
194194 pub fn from_path ( path : Utf8PathBuf , filter : Option < String > ) -> anyhow:: Result < Self > {
195+ log:: info!( "Searching for pages in {:?}" , path) ;
195196 let mut page_paths = Vec :: new ( ) ;
196197
197198 let path = Utf8PathBuf :: from (
@@ -202,32 +203,50 @@ impl Book {
202203 . canonicalize_utf8 ( )
203204 . map_err ( |e| anyhow:: anyhow!( "failed to canonicalize path: {}" , e) ) ?;
204205
206+ log:: info!( "Canonicalized path: {:?}" , path) ;
207+
205208 if path. is_file ( ) {
209+ log:: info!( "Path is a file" ) ;
206210 eval_if_in_filter ! ( path, filter, page_paths. push( path. to_path_buf( ) ) ) ;
207211 } else if path. is_dir ( ) {
208- for entry in glob ( path. join ( "**/*.yml" ) . as_str ( ) ) ? {
212+ log:: info!( "Path is a directory, searching for .yml files" ) ;
213+ let glob_pattern = path. join ( "**/*.yml" ) . as_str ( ) . to_string ( ) ;
214+ log:: info!( "Using glob pattern: {}" , glob_pattern) ;
215+
216+ for entry in glob ( & glob_pattern) ? {
209217 match entry {
210218 Ok ( entry_path) => {
211- // skip hidden files and folders to avoid loading .git and .github directories
212- if entry_path. components ( ) . any ( |component| {
213- component. as_os_str ( ) . to_string_lossy ( ) . starts_with ( "." )
214- } ) {
215- continue ;
219+ log:: info!( "Found file: {:?}" , entry_path) ;
220+ // skip files in hidden directories (starting with .)
221+ // but allow the root .robopages directory
222+ if let Ok ( relative_path) = entry_path. strip_prefix ( & path) {
223+ if relative_path. components ( ) . any ( |component| {
224+ let comp_str = component. as_os_str ( ) . to_string_lossy ( ) ;
225+ comp_str. starts_with ( "." ) && comp_str != "." && comp_str != ".."
226+ } ) {
227+ log:: info!( "Skipping hidden file/directory" ) ;
228+ continue ;
229+ }
216230 }
217231
218232 if let Ok ( utf8_path) = Utf8PathBuf :: from_path_buf ( entry_path) {
219- eval_if_in_filter ! ( utf8_path, filter, page_paths. push( utf8_path) ) ;
233+ eval_if_in_filter ! ( utf8_path, filter, {
234+ log:: info!( "Adding path: {:?}" , utf8_path) ;
235+ page_paths. push( utf8_path) ;
236+ } ) ;
220237 } else {
221238 log:: error!( "failed to convert path to Utf8PathBuf" ) ;
222239 }
223240 }
224241 Err ( e) => {
225- log:: error!( "error in glob pattern : {:? }" , e) ;
242+ log:: error!( "Error in glob: {}" , e) ;
226243 }
227244 }
228245 }
229246 }
230247
248+ log:: info!( "Found {} page paths" , page_paths. len( ) ) ;
249+
231250 if page_paths. is_empty ( ) {
232251 return Err ( anyhow:: anyhow!( "no pages found in {:?}" , path) ) ;
233252 }
@@ -248,16 +267,18 @@ impl Book {
248267
249268 // if categories are not set, use the path components
250269 if page. categories . is_empty ( ) {
251- page. categories = page_path
252- . strip_prefix ( & path)
253- . unwrap ( )
254- . parent ( )
255- . map ( |p| {
256- p. components ( )
257- . map ( |c| c. as_os_str ( ) . to_string_lossy ( ) . into_owned ( ) )
258- . collect ( )
259- } )
260- . unwrap_or_default ( ) ;
270+ let path_buf = page_path. strip_prefix ( & path) ?;
271+ let parent = path_buf. parent ( ) ;
272+
273+ if let Some ( parent_path) = parent {
274+ page. categories = parent_path
275+ . components ( )
276+ . map ( |c| c. as_str ( ) . to_string ( ) )
277+ . collect ( ) ;
278+
279+ // Skip empty categories
280+ page. categories . retain ( |c| !c. is_empty ( ) ) ;
281+ }
261282 }
262283
263284 // make sure function names are unique
0 commit comments