Skip to content

Commit fff42a4

Browse files
committed
create sitze aliases
1 parent 85ea6dc commit fff42a4

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

builder/src/website_builder.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::fs;
22
use std::io::Write;
33
use std::path::PathBuf;
4+
use itertools::Itertools;
45
use lewp_css::domain::at_rules::font_face::FontDisplay::fallback;
56
use regex::Regex;
67

@@ -10,7 +11,7 @@ use crate::ir::IR;
1011
use crate::sitemapper::SiteMapBuilder;
1112

1213
pub struct Website {
13-
pages: Vec<(PathBuf, Vec<u8>)>,
14+
pub pages: Vec<(PathBuf, Vec<u8>)>,
1415
}
1516

1617
impl 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

Comments
 (0)