@@ -7,6 +7,7 @@ use crate::teams::{encode_zulip_stream, load_rust_teams};
7
7
use anyhow:: Context ;
8
8
use handlebars:: { DirectorySourceOptions , Handlebars } ;
9
9
use handlebars_fluent:: FluentHelper ;
10
+ use std:: ffi:: OsStr ;
10
11
use std:: path:: { Path , PathBuf } ;
11
12
12
13
mod assets;
@@ -94,7 +95,7 @@ fn main() -> anyhow::Result<()> {
94
95
rust_version,
95
96
teams,
96
97
handlebars,
97
- output_dir,
98
+ output_dir : output_dir . clone ( ) ,
98
99
base_url,
99
100
} ;
100
101
ctx. copy_asset_dir ( "static" , "static" ) ?;
@@ -113,5 +114,42 @@ fn main() -> anyhow::Result<()> {
113
114
ctx. page ( "404" , "" , & ( ) , ENGLISH ) . render ( "404.html" ) ?;
114
115
create_redirects ( & ctx) ?;
115
116
117
+ sanity_check_index_pages ( & output_dir) ?;
118
+
119
+ Ok ( ( ) )
120
+ }
121
+
122
+ /// Make sure that there are no instances where we would have both `<page>.html` and
123
+ /// a `<page>` directory.
124
+ fn sanity_check_index_pages ( directory : & Path ) -> anyhow:: Result < ( ) > {
125
+ // Find all .html files
126
+ let mut html_files = vec ! [ ] ;
127
+ gather_html_files ( directory, & mut html_files) ?;
128
+
129
+ for file in html_files {
130
+ let basename = file. file_stem ( ) . unwrap ( ) ;
131
+ let dir = file. parent ( ) . unwrap ( ) . join ( basename) ;
132
+ if dir. is_dir ( ) {
133
+ return Err ( anyhow:: anyhow!(
134
+ "Both the `{file}` file and the `{dir}` directory exist, move `{file}` to `{dir_index}` instead" ,
135
+ file = file. display( ) ,
136
+ dir = dir. display( ) ,
137
+ dir_index = dir. join( "index.html" ) . display( )
138
+ ) ) ;
139
+ }
140
+ }
141
+
142
+ Ok ( ( ) )
143
+ }
144
+
145
+ fn gather_html_files ( path : & Path , files : & mut Vec < PathBuf > ) -> anyhow:: Result < ( ) > {
146
+ if path. is_file ( ) && path. extension ( ) == Some ( OsStr :: new ( "html" ) ) {
147
+ files. push ( path. to_path_buf ( ) ) ;
148
+ } else if path. is_dir ( ) {
149
+ for entry in path. read_dir ( ) ? {
150
+ let entry = entry?;
151
+ gather_html_files ( & entry. path ( ) , files) ?;
152
+ }
153
+ }
116
154
Ok ( ( ) )
117
155
}
0 commit comments