const DEFAULT_BUF_SIZE: usize = 16 * 1024;
pub fn read_styles(path: &std::path::Path) -> Result<String, std::io::Error> {
if path.is_dir() {
let combined = std::fs::read_dir(path)?
.filter_map(Result::ok)
.filter_map(|e| {
e.path()
.extension()
.is_some_and(|e| e.eq_ignore_ascii_case("css"))
.then_some(e.path())
})
.filter_map(|path| match std::fs::read_to_string(&path) {
Err(e) => {
log::warn!("Failed to read file {path:?}\n{e}");
None
}
Ok(v) => Some(v),
})
.fold(String::with_capacity(DEFAULT_BUF_SIZE), |mut s, c| {
s.push_str(&c);
s
});
Ok(combined)
} else {
Ok(std::fs::read_to_string(path)?)
}
}