This commit is contained in:
Mylloon 2024-11-12 01:14:48 +01:00
parent aaf228c32d
commit 411ea64fcb
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
3 changed files with 9 additions and 10 deletions

1
Cargo.lock generated
View file

@ -1095,6 +1095,7 @@ dependencies = [
"serde_yml", "serde_yml",
"toml", "toml",
"urlencoding", "urlencoding",
"walkdir",
] ]
[[package]] [[package]]

View file

@ -32,6 +32,7 @@ mime_guess = "2.0"
urlencoding = "2.1" urlencoding = "2.1"
regex = "1.10" regex = "1.10"
cyborgtime = "2.1.1" cyborgtime = "2.1.1"
walkdir = "2.5"
[lints.clippy] [lints.clippy]
pedantic = "warn" pedantic = "warn"

View file

@ -12,6 +12,7 @@ use chrono::{DateTime, Datelike, Local, NaiveDateTime, Utc};
use chrono_tz::Europe; use chrono_tz::Europe;
use comrak::{parse_document, Arena}; use comrak::{parse_document, Arena};
use ramhorns::Content; use ramhorns::Content;
use walkdir::WalkDir;
use crate::{ use crate::{
config::Config, config::Config,
@ -59,16 +60,12 @@ impl Hash for Post {
} }
pub fn get_posts(location: &str) -> Vec<Post> { pub fn get_posts(location: &str) -> Vec<Post> {
std::fs::read_dir(location) WalkDir::new(location)
.map_or_else( .into_iter()
|_| vec![], .filter_map(Result::ok)
|res| { .filter(|entry| {
res.flatten() entry.file_type().is_file() && entry.path().extension().is_some_and(|s| s == "md")
.filter(|f| f.path().extension().map_or(false, |ext| ext == "md")) })
.collect::<Vec<std::fs::DirEntry>>()
},
)
.iter()
.filter_map(|f| { .filter_map(|f| {
let fname = f.file_name(); let fname = f.file_name();
let filename = fname.to_string_lossy(); let filename = fname.to_string_lossy();