11use std:: fs;
22use std:: io:: Write ;
33use std:: path:: PathBuf ;
4+ use itertools:: Itertools ;
45use lewp_css:: domain:: at_rules:: font_face:: FontDisplay :: fallback;
56use regex:: Regex ;
67
@@ -10,7 +11,7 @@ use crate::ir::IR;
1011use crate :: sitemapper:: SiteMapBuilder ;
1112
1213pub struct Website {
13- pages : Vec < ( PathBuf , Vec < u8 > ) > ,
14+ pub pages : Vec < ( PathBuf , Vec < u8 > ) > ,
1415}
1516
1617impl Website {
@@ -41,6 +42,23 @@ impl Website {
4142 }
4243 }
4344
45+ println ! ( "Creating aliases:" ) ;
46+ let mut aliases = Vec :: new ( ) ;
47+ for ( path, content) in & build_pages {
48+ let path = path. to_str ( ) . unwrap ( ) ;
49+ if path. ends_with ( ".html" ) && !path. ends_with ( "index.html" ) {
50+ let name = path. split ( '/' ) . last ( ) . unwrap ( ) . strip_suffix ( ".html" ) . unwrap ( ) ;
51+ println ! ( "> {}" , & path) ;
52+
53+ let idx_path = path. replace ( format ! ( "{name}.html" ) . as_str ( ) , format ! ( "{name}/index.html" ) . as_str ( ) ) ;
54+ println ! ( " - {}" , & idx_path) ;
55+ aliases. push ( ( PathBuf :: from ( idx_path) , content. clone ( ) ) ) ;
56+ }
57+ }
58+ println ! ( "> {} aliases created" , & aliases. len( ) ) ;
59+
60+ build_pages. append ( & mut aliases) ;
61+
4462 println ! ( "Building sitemap:" ) ;
4563 build_pages. push ( ( PathBuf :: from ( "sitemap.xml" ) , sitemap. build ( ) . as_bytes ( ) . to_vec ( ) ) ) ;
4664
@@ -92,6 +110,7 @@ impl Website {
92110 fs:: create_dir_all ( parent) ?;
93111 }
94112
113+ println ! ( "writing {:?}" , & path) ;
95114 let mut file = fs:: File :: create ( path) ?;
96115 file. write_all ( content) ?;
97116 Ok ( ( ) )
0 commit comments