feat: allow for overlapping festivals

This commit is contained in:
silver 2025-06-10 16:54:13 +01:00
parent 1555a94656
commit 51d5904ffd
Signed by: silver
GPG key ID: 36F93D61BAD3FD7D

View file

@ -107,7 +107,7 @@ async fn update_icon_main(ctx: Arc<Context>) {
}
struct FestivalData{
current: Option<String>,
current: Vec<String>,
exclusions: Vec<String>,
}
@ -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<LogoData> {
fn logos_filter(festival_data: &FestivalData, existing: Vec<LogoData>) -> Vec<LogoData>{
let mut filtered: Vec<LogoData> = 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);
}
}