Added config option for how many recently updated entries to show and also showing the date of the update

main
Wynd 2023-11-11 00:58:16 +02:00
parent e5a0ccdb53
commit 1ffd130472
1 changed files with 13 additions and 3 deletions

View File

@ -72,6 +72,15 @@ impl Preprocessor for LastChanged {
}
});
let size = match ctx.config.get("output.html.recently-updated-size") {
Some(val) => match val {
toml::Value::Integer(i) => i,
_ => &5
},
None => &5,
}.to_owned();
let size = usize::try_from(size).expect("Recently Updated size is not an usize");
let mut vec: Vec<(LiteLink, NaiveDate)> = map
.into_iter()
.map(|e| (e.0, NaiveDate::from_str(&e.1).unwrap()))
@ -79,15 +88,16 @@ impl Preprocessor for LastChanged {
// Sorting alphabetically and then by date, this means same date entries will be sorted alphabetically, otherwise the end result will be randomized when truncating
vec.sort_by(|a, b| a.0.name.cmp(&b.0.name));
vec.sort_by(|a, b| b.1.cmp(&a.1));
vec.truncate(5);
vec.truncate(size);
let text: String = vec
.into_iter()
.map(|f| {
format!(
"<li><a href=\"{}\">{}</a></li>",
"<li><a href=\"{}\">{}</a> - {}</li>",
f.0.path.unwrap().display(),
f.0.name
f.0.name,
f.1.to_string()
)
})
.collect();