sort order index item by date desc

This commit is contained in:
yggverse 2025-02-12 20:07:26 +02:00
parent 774a05acfe
commit a22fa6449a

View file

@ -102,14 +102,18 @@ fn crawl(argument: &Argument, output: &Output) -> Result<(), Box<dyn Error>> {
// renew pending index files on items crawl completed
if let Some(ref index_argument) = argument.index {
for path in index {
let subject = format!("{path}{index_argument}");
let index_filename = format!("{path}{index_argument}");
// scan dir files, sort by name desc
let mut files: Vec<_> = read_dir(&path)?.filter_map(Result::ok).collect();
files.sort_by_key(|f| f.file_name());
let mut index = File::create(&subject)?;
let mut data = Vec::with_capacity(argument.limit);
let mut index = File::create(&index_filename)?;
let mut total = 0;
for file in read_dir(&path)? {
let name = file?.file_name().into_string().unwrap();
for file in files {
let name = file.file_name().into_string().unwrap();
if &name == index_argument {
continue;
@ -124,7 +128,7 @@ fn crawl(argument: &Argument, output: &Output) -> Result<(), Box<dyn Error>> {
index.write_all(data.join("\n\n").as_bytes())?;
output.debug(&format!("renew `{subject}` (total: {total})"));
output.debug(&format!("renew `{index_filename}` (total: {total})"));
}
}