From 51d5904ffdfc71e087e96624b49df0135db68932 Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Tue, 10 Jun 2025 16:54:13 +0100 Subject: [PATCH] feat: allow for overlapping festivals --- src/bin/update_server-icon.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/bin/update_server-icon.rs b/src/bin/update_server-icon.rs index 56a6f0b..d161352 100644 --- a/src/bin/update_server-icon.rs +++ b/src/bin/update_server-icon.rs @@ -107,7 +107,7 @@ async fn update_icon_main(ctx: Arc) { } struct FestivalData{ - current: Option, + current: Vec, exclusions: Vec, } @@ -118,7 +118,7 @@ fn get_festival(config_toml: &ConfigToml)-> FestivalData { let year = today.year(); let mut result = FestivalData { - current: None, + current: vec![], exclusions: vec![], }; @@ -126,9 +126,9 @@ fn get_festival(config_toml: &ConfigToml)-> FestivalData { if (day >= festival.start.day && day <= festival.end.day) && (month >= festival.start.month && month <= festival.end.month ) { if festival.start.year == 0 || festival.end.year == 0 { - result.current = Some(festival.name.to_owned()); + result.current.push(festival.name.to_owned()); } else if (year >= festival.start.year && year <= festival.end.year) { - result.current = Some(festival.name.to_owned()); + result.current.push(festival.name.to_owned()); } } else if !festival.all_year { result.exclusions.push(festival.name.to_owned()); @@ -279,27 +279,27 @@ fn get_logos(config: &Config, config_toml: &ConfigToml) -> Vec { fn logos_filter(festival_data: &FestivalData, existing: Vec) -> Vec{ let mut filtered: Vec = vec![]; - for logo in existing { + 'outer: for logo in existing { let name_lowercase0 = logo.name.to_ascii_lowercase(); let name_lowercase = name_lowercase0.to_str().unwrap_or_default(); // if its a current festival filter based on it - if let Some(x) = &festival_data.current { - if name_lowercase.contains(x) { + for festival in &festival_data.current { + if name_lowercase.contains(festival) { filtered.push(logo); + continue 'outer; } - } else { - // else filter using the excluded ones - let mut excluded = false; - for festival in &festival_data.exclusions { - if name_lowercase.contains(festival) { - excluded = true; - } + } + // else filter using the excluded ones + let mut excluded = false; + for festival in &festival_data.exclusions { + if name_lowercase.contains(festival) { + excluded = true; } + } - if !excluded { - filtered.push(logo); - } + if !excluded { + filtered.push(logo); } }