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() {
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)
}
}

View File

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