File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ use std::io::Write;
33use std:: path:: PathBuf ;
44use itertools:: Itertools ;
55use lewp_css:: domain:: at_rules:: font_face:: FontDisplay :: fallback;
6- use regex:: Regex ;
6+ use regex:: { Regex , Replacer } ;
77
88use crate :: builder:: BuildProcedureBuildError ;
99use crate :: fs_tree:: ParsedFsEntry ;
@@ -49,10 +49,15 @@ impl Website {
4949 if path. ends_with ( ".html" ) && !path. ends_with ( "index.html" ) {
5050 let name = path. split ( '/' ) . last ( ) . unwrap ( ) . strip_suffix ( ".html" ) . unwrap ( ) ;
5151 println ! ( "> {}" , & path) ;
52+
53+ let cannonical = format ! ( "<link rel=\" canonical\" href=\" /{path}\" />" ) ;
54+ let content = String :: from_utf8 ( content. clone ( ) ) . expect ( "html files are utf8" )
55+ . replacen ( "</head>" , format ! ( "{cannonical}</head>" ) . as_str ( ) , 1 )
56+ . as_bytes ( ) . to_vec ( ) ;
5257
5358 let idx_path = path. replace ( format ! ( "{name}.html" ) . as_str ( ) , format ! ( "{name}/index.html" ) . as_str ( ) ) ;
5459 println ! ( " - {}" , & idx_path) ;
55- aliases. push ( ( PathBuf :: from ( idx_path) , content. clone ( ) ) ) ;
60+ aliases. push ( ( PathBuf :: from ( idx_path) , content) ) ;
5661 }
5762 }
5863 println ! ( "> {} aliases created" , & aliases. len( ) ) ;
You can’t perform that action at this time.
0 commit comments