fix: use a struct for clarity
This commit is contained in:
parent
b4f6835704
commit
a7423959dc
1 changed files with 25 additions and 11 deletions
|
@ -94,26 +94,33 @@ async fn update_icon_main(ctx: Arc<Context>) {
|
|||
let logos = get_logos(&config_global, &config_toml);
|
||||
}
|
||||
|
||||
fn get_festival(config_toml: &ConfigToml)-> (Option<String>, Vec<String>){
|
||||
struct FestivalData{
|
||||
current: Option<String>,
|
||||
exclusions: Vec<String>,
|
||||
}
|
||||
|
||||
fn get_festival(config_toml: &ConfigToml)-> FestivalData {
|
||||
let today = Utc::now();
|
||||
let day = today.day();
|
||||
let month = today.month();
|
||||
let year = today.year();
|
||||
|
||||
let mut festival_current = None;
|
||||
let mut festival_not = vec![];
|
||||
let mut result = FestivalData {
|
||||
current: None,
|
||||
exclusions: vec![],
|
||||
};
|
||||
|
||||
for festival in &config_toml.festivals {
|
||||
if (day >= festival.start.day && day <= festival.end.day)
|
||||
&& (month >= festival.start.month && month <= festival.end.month )
|
||||
&& (year >= festival.start.year && year <= festival.end.year) {
|
||||
festival_current = Some(festival.name.to_owned());
|
||||
result.current = Some(festival.name.to_owned());
|
||||
} else if !festival.all_year {
|
||||
festival_not.push(festival.name.to_owned());
|
||||
result.exclusions.push(festival.name.to_owned());
|
||||
}
|
||||
}
|
||||
|
||||
(festival_current, festival_not)
|
||||
result
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
@ -184,7 +191,11 @@ fn convert_svg_to_png(original: &PathBuf, out: &PathBuf){
|
|||
fs::write(out, &bytes).expect("TODO: panic message");
|
||||
}
|
||||
|
||||
fn get_logos(config: &Config, config_toml: &ConfigToml) -> Vec<(OsString, PathBuf)> {
|
||||
struct LogoData {
|
||||
name: OsString,
|
||||
path: PathBuf,
|
||||
}
|
||||
fn get_logos(config: &Config, config_toml: &ConfigToml) -> Vec<LogoData> {
|
||||
let folder = format!("{}/open-governance/{}", &config.home, &config_toml.source.directory);
|
||||
let folder_path = PathBuf::from(&folder);
|
||||
let paths = fs::read_dir(folder).unwrap();
|
||||
|
@ -203,8 +214,8 @@ fn get_logos(config: &Config, config_toml: &ConfigToml) -> Vec<(OsString, PathB
|
|||
for tmp in paths.flatten() {
|
||||
let path_local = tmp.path().to_owned();
|
||||
let path_local2 = tmp.path().to_owned();
|
||||
let temp2 = path_local2.file_name().unwrap();
|
||||
let mut file_path = tmp.path();
|
||||
let name = path_local2.file_name().unwrap().to_owned();
|
||||
let mut path = tmp.path();
|
||||
|
||||
match tmp.path().extension() {
|
||||
None => {}
|
||||
|
@ -220,12 +231,15 @@ fn get_logos(config: &Config, config_toml: &ConfigToml) -> Vec<(OsString, PathB
|
|||
log::error!("Failed to render {path_local:?}: {}", e)
|
||||
}
|
||||
}
|
||||
file_path = path_new;
|
||||
path = path_new;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
logos.push((temp2.to_owned(), file_path.to_owned()));
|
||||
logos.push(LogoData{
|
||||
name,
|
||||
path,
|
||||
});
|
||||
|
||||
println!("Name: {}", &tmp.path().display());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue