fix: preserve discovery order

This commit is contained in:
əlemi 2024-10-20 05:56:38 +02:00
parent 0af5adec5a
commit 083e605255
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 12 additions and 6 deletions

2
Cargo.lock generated
View file

@ -815,7 +815,7 @@ checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2"
[[package]] [[package]]
name = "postwoman" name = "postwoman"
version = "0.3.1" version = "0.3.2"
dependencies = [ dependencies = [
"base64", "base64",
"chrono", "chrono",

View file

@ -6,6 +6,7 @@ use std::{collections::HashMap, str::FromStr};
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use indexmap::IndexMap;
pub use model::PostWomanCollection; pub use model::PostWomanCollection;
pub use errors::PostWomanError; pub use errors::PostWomanError;
@ -66,7 +67,7 @@ fn main() {
} }
} }
let mut collections = HashMap::new(); let mut collections = IndexMap::new();
if !load_collections(&mut collections, args.collection.clone()) { if !load_collections(&mut collections, args.collection.clone()) {
return; return;
@ -104,7 +105,7 @@ fn main() {
} }
} }
fn load_collections(store: &mut HashMap<String, PostWomanCollection>, mut path: std::path::PathBuf) -> bool { fn load_collections(store: &mut IndexMap<String, PostWomanCollection>, mut path: std::path::PathBuf) -> bool {
let collection_raw = match std::fs::read_to_string(&path) { let collection_raw = match std::fs::read_to_string(&path) {
Ok(x) => x, Ok(x) => x,
Err(e) => { Err(e) => {
@ -122,6 +123,7 @@ fn load_collections(store: &mut HashMap<String, PostWomanCollection>, mut path:
}; };
let name = path.to_string_lossy().to_string(); let name = path.to_string_lossy().to_string();
let mut to_include = Vec::new();
if let Some(ref includes) = collection.include { if let Some(ref includes) = collection.include {
path.pop(); path.pop();
@ -129,14 +131,18 @@ fn load_collections(store: &mut HashMap<String, PostWomanCollection>, mut path:
let mut base = path.clone(); let mut base = path.clone();
let new = std::path::PathBuf::from_str(include).expect("infallible"); let new = std::path::PathBuf::from_str(include).expect("infallible");
base.push(new); base.push(new);
if !load_collections(store, base) { to_include.push(base);
return false;
}
} }
} }
store.insert(name, collection); store.insert(name, collection);
for base in to_include {
if !load_collections(store, base) {
return false;
}
}
true true
} }