get covers from children if no images in album
This commit is contained in:
parent
584ec41c7a
commit
90482446b1
4 changed files with 32 additions and 17 deletions
|
|
@ -11,7 +11,7 @@ use std::slice::Iter;
|
|||
pub struct AlbumDir {
|
||||
pub path: PathBuf,
|
||||
pub images: Vec<Image>,
|
||||
pub cover: Option<Image>,
|
||||
pub cover: Image,
|
||||
pub children: Vec<AlbumDir>,
|
||||
|
||||
pub description: String,
|
||||
|
|
@ -99,11 +99,23 @@ impl AlbumDir {
|
|||
}
|
||||
}
|
||||
|
||||
if cover.is_none() && !images.is_empty() {
|
||||
cover = Some(images[0].clone());
|
||||
}
|
||||
// TODO: sort children and albums alphabetically
|
||||
|
||||
// Find a cover image if we didn't have an explicit one. Either the first image, or the
|
||||
// first image from the first album that has a cover.
|
||||
if cover.is_none() {
|
||||
if !images.is_empty() {
|
||||
cover = Some(images[0].clone());
|
||||
} else {
|
||||
// Find a cover image from one of the children
|
||||
if !children.is_empty() {
|
||||
cover = Some(children[0].cover.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
let cover = cover.ok_or(anyhow!("Could not find a cover image for {}", p.display()))?;
|
||||
log::debug!("Cover for {} is {cover:?}", p.display());
|
||||
|
||||
Ok(AlbumDir {
|
||||
path: p.strip_prefix(root)?.to_path_buf(),
|
||||
images,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue