Fix archive not being sorted

This commit is contained in:
Shadowfacts 2025-02-11 20:53:18 -05:00
parent 76f6244814
commit 6cf9d85516
3 changed files with 13 additions and 11 deletions

View File

@ -77,6 +77,10 @@ impl Rule for PostsByYear {
for entry in self.input_0().iter().cloned() { for entry in self.input_0().iter().cloned() {
map.entry(entry.date.year()).or_insert(vec![]).push(entry); map.entry(entry.date.year()).or_insert(vec![]).push(entry);
} }
for year_vec in map.values_mut() {
year_vec.sort_by_key(|ent| ent.date);
year_vec.reverse();
}
PostsYearMap(map) PostsYearMap(map)
} }
} }

View File

@ -66,23 +66,21 @@ impl Rule for ListPostFiles {
type Output = Vec<PathBuf>; type Output = Vec<PathBuf>;
fn evaluate(&mut self) -> Self::Output { fn evaluate(&mut self) -> Self::Output {
let posts_path = content_path("posts/"); let posts_path = content_path("posts/");
let entries = std::fs::read_dir(posts_path); let entries = std::fs::read_dir(posts_path).expect("listing posts dir");
match entries { entries
Ok(entries) => entries .flat_map(|year_ent| year_ent.ok())
.flat_map(|ent| ent.ok()) .filter(|year_ent| year_ent.file_type().unwrap().is_dir())
.map(|ent| { .flat_map(|year_ent| {
let year_entries = std::fs::read_dir(year_ent.path()).expect("listing year dir");
year_entries.flat_map(|ent| ent.ok()).map(|ent| {
if ent.file_type().unwrap().is_dir() { if ent.file_type().unwrap().is_dir() {
find_index(ent.path()).expect("folder posts must have index file") find_index(ent.path()).expect("folder posts must have index file")
} else { } else {
ent.path() ent.path()
} }
}) })
.collect(), })
Err(e) => { .collect::<Vec<_>>()
error!("Error listing posts: {e:?}");
vec![]
}
}
} }
} }