@@ -70,31 +70,32 @@ func buildRouter(rtr chi.Router, fileSystem fs.FS, options Options) {
70
70
for _ , file := range files {
71
71
name := file .Name ()
72
72
73
- // ...if it's a directory, create a sub-route by
74
- // recursively calling `buildRouter`
75
- if file .IsDir () {
76
- sub , err := fs .Sub (fileSystem , name )
77
- if err != nil {
78
- options .Logger .Error (context .Background (), "Unable to call fs.Sub on directory" , slog .F ("directory_name" , name ))
79
- continue
80
- }
81
-
82
- // In the special case where the folder is dynamic,
83
- // like `[org]`, we can convert to a chi-style dynamic route
84
- // (which uses `{` instead of `[`)
85
- routeName := name
86
- if isDynamicRoute (name ) {
87
- routeName = "{dynamic}"
88
- }
89
-
90
- options .Logger .Debug (context .Background (), "Adding route" , slog .F ("name" , name ), slog .F ("routeName" , routeName ))
91
- rtr .Route ("/" + routeName , func (r chi.Router ) {
92
- buildRouter (r , sub , options )
93
- })
94
- } else {
95
- // ...otherwise, if it's a file - serve it up!
73
+ // If we're working with a file - just serve it up
74
+ if ! file .IsDir () {
96
75
serveFile (rtr , fileSystem , name , options )
76
+ continue
77
+ }
78
+
79
+ // ...otherwise, if it's a directory, create a sub-route by
80
+ // recursively calling `buildRouter`
81
+ sub , err := fs .Sub (fileSystem , name )
82
+ if err != nil {
83
+ options .Logger .Error (context .Background (), "Unable to call fs.Sub on directory" , slog .F ("directory_name" , name ))
84
+ continue
85
+ }
86
+
87
+ // In the special case where the folder is dynamic,
88
+ // like `[org]`, we can convert to a chi-style dynamic route
89
+ // (which uses `{` instead of `[`)
90
+ routeName := name
91
+ if isDynamicRoute (name ) {
92
+ routeName = "{dynamic}"
97
93
}
94
+
95
+ options .Logger .Debug (context .Background (), "Adding route" , slog .F ("name" , name ), slog .F ("routeName" , routeName ))
96
+ rtr .Route ("/" + routeName , func (r chi.Router ) {
97
+ buildRouter (r , sub , options )
98
+ })
98
99
}
99
100
}
100
101
0 commit comments