setu_cli/finder.rs
1use std::{
2 fs::{self, DirEntry},
3 path::PathBuf,
4};
5
6pub fn get_markdowns(target_path: &str) -> Vec<PathBuf> {
7 fs::read_dir(target_path)
8 .map(|read_dir| {
9 read_dir
10 .flatten()
11 .filter(|entry| is_markdown(entry))
12 .map(|entry| entry.path())
13 .collect()
14 })
15 .unwrap_or_else(|_| Vec::new())
16}
17
18pub fn is_markdown(entry: &DirEntry) -> bool {
19 entry
20 .path()
21 .extension()
22 .map(|ext| ext == "md" || ext == "markdown")
23 .unwrap_or(false)
24}