routes_map.rs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. use std::path::PathBuf;
  2. use std::fs;
  3. #[derive(Debug)]
  4. pub enum FileType {
  5. HtmlIndex(PathBuf),
  6. NeovanIndex(PathBuf),
  7. HtmlComponent(PathBuf),
  8. NeovanComponent(PathBuf)
  9. }
  10. impl FileType {
  11. pub fn get_all(dir: PathBuf) -> Vec<FileType> {
  12. let entries = fs::read_dir(dir).expect("Create failed");
  13. let mut files = Vec::new();
  14. for entry in entries {
  15. let path = entry.expect("Failed to read directory").path();
  16. if path.is_dir() {
  17. files.append(&mut FileType::get_all(path));
  18. } else if path.is_file() {
  19. let filename = path.file_name().expect("Error reading file").to_string_lossy();
  20. if filename == "index.html" {
  21. files.push(FileType::HtmlIndex(path))
  22. } else if filename == "index.neovan" {
  23. files.push(FileType::NeovanIndex(path))
  24. } else if let Some(ext) = path.extension() {
  25. if ext == "html" {
  26. files.push(FileType::HtmlComponent(path))
  27. } else if ext == "neovan" {
  28. files.push(FileType::NeovanComponent(path))
  29. }
  30. }
  31. }
  32. }
  33. files
  34. }
  35. }