Markdown files with a ` ` extension in `dir`, sorted by path. Returns an empty list when `dir` does not exist.
(dir: &Path, exts: &[&str])
| 186 | /// Markdown files with a `<ext>` extension in `dir`, sorted by path. Returns an |
| 187 | /// empty list when `dir` does not exist. |
| 188 | fn md_files(dir: &Path, exts: &[&str]) -> Result<Vec<PathBuf>> { |
| 189 | if !dir.is_dir() { |
| 190 | return Ok(Vec::new()); |
| 191 | } |
| 192 | let mut entries: Vec<PathBuf> = std::fs::read_dir(dir) |
| 193 | .map_err(|e| CodeError::Context(format!("read {}: {e}", dir.display())))? |
| 194 | .filter_map(|e| e.ok().map(|e| e.path())) |
| 195 | .filter(|p| { |
| 196 | p.extension() |
| 197 | .and_then(|s| s.to_str()) |
| 198 | .map(|e| exts.contains(&e)) |
| 199 | .unwrap_or(false) |
| 200 | }) |
| 201 | .collect(); |
| 202 | entries.sort(); |
| 203 | Ok(entries) |
| 204 | } |
| 205 | |
| 206 | fn load_schedules(dir: &Path) -> Result<Vec<ScheduleSpec>> { |
| 207 | let mut out = Vec::new(); |
no test coverage detected