diff --git a/src/build/collection.rs b/src/build/collection.rs index 615f27f..0cd401a 100644 --- a/src/build/collection.rs +++ b/src/build/collection.rs @@ -4,6 +4,7 @@ use indoc::formatdoc; use crate::{Collection, Context, Site}; use crate::build::Breadcrumb; +use crate::build::playlist::banner_html; use crate::build::render::{layout, thumbnail}; pub fn collection_html( @@ -64,7 +65,16 @@ pub fn collection_html( let slug = playlist.slug(); let title = playlist.title.as_deref().unwrap_or_else(|| playlist.slug()); + let playlist_prefix = format!("{slug}/"); + + let banner = if let Some(banner) = &playlist.banner { + banner_html(banner, &playlist_prefix) + } else { + String::new() + }; + formatdoc!(r#" + {banner} {title} "#) }) diff --git a/src/build/playlist.rs b/src/build/playlist.rs index ca4b53c..3793e48 100644 --- a/src/build/playlist.rs +++ b/src/build/playlist.rs @@ -2,10 +2,29 @@ use std::fs; use indoc::formatdoc; -use crate::{Context, Playlist, Site}; +use crate::{Banner, Context, Playlist, Site}; use crate::build::Breadcrumb; use crate::build::render::{layout, thumbnail}; +pub fn banner_html(banner: &Banner, playlist_prefix: &str) -> String { + let alt = if let Some(description) = &banner.description { + format!(r#"alt="{description}" "#) + } else { + String::new() + }; + + if let Some(poster_assets) = &banner.assets { + // TODO: Adjust up_to_xxx (depends on final content width we're using) + let image_attributes = poster_assets.img_attributes_up_to_1280("banner", playlist_prefix); + let src = image_attributes.src; + let srcset = image_attributes.srcset; + + formatdoc!(r#""#) + } else { + formatdoc!(r#""#) + } +} + pub fn playlist_html( context: &Context, playlist: &Playlist, @@ -21,6 +40,12 @@ pub fn playlist_html( playlist.title.as_deref().unwrap_or_else(|| playlist.slug()) }; + if let Some(banner) = &playlist.banner { + let playlist_prefix = ""; + let img = banner_html(banner, playlist_prefix); + body.push_str(&img); + } + body.push_str(&format!("

{title}

\n\n")); if let Some(description) = &playlist.description { diff --git a/src/build/render.rs b/src/build/render.rs index d594c36..94f458a 100644 --- a/src/build/render.rs +++ b/src/build/render.rs @@ -366,7 +366,7 @@ pub fn thumbnail(video: &Video, video_prefix: &str) -> String { match &video.poster { Some(poster) => { if let Some(poster_assets) = &poster.assets { - let image_attributes = poster_assets.img_attributes_up_to_480(video_prefix); + let image_attributes = poster_assets.img_attributes_up_to_480("poster", video_prefix); let src = image_attributes.src; let srcset = image_attributes.srcset; diff --git a/src/poster.rs b/src/poster.rs index 7be172d..9c6a2c8 100644 --- a/src/poster.rs +++ b/src/poster.rs @@ -60,6 +60,7 @@ impl ImgAttributes { /// Assets MUST be passed in ascending size pub fn new( assets_ascending_by_size: Vec<&PosterAsset>, + base_name: &str, prefix: &str ) -> ImgAttributes { let mut src = String::new(); @@ -68,10 +69,13 @@ impl ImgAttributes { let mut asset_peek_iter = assets_ascending_by_size.iter().peekable(); while let Some(asset) = asset_peek_iter.next() { - srcset.push(format!("{}poster_{}x{}.jpg {}w", prefix, asset.width, asset.height, asset.width)); + let height = asset.height; + let width = asset.width; + + srcset.push(format!("{prefix}{base_name}_{width}x{height}.jpg {width}w")); if asset_peek_iter.peek().is_none() { - src = format!("{}poster_{}x{}.jpg", prefix, asset.width, asset.height); + src = format!("{prefix}{base_name}_{width}x{height}.jpg"); } } @@ -95,16 +99,16 @@ impl PosterAssets { result } - pub fn img_attributes_up_to_320(&self, prefix: &str) -> ImgAttributes { + pub fn img_attributes_up_to_320(&self, base_name: &str, prefix: &str) -> ImgAttributes { let assets = match &self.max_320 { Some(max_320) => vec![&self.max_160, max_320], None => vec![&self.max_160] }; - ImgAttributes::new(assets, prefix) + ImgAttributes::new(assets, base_name, prefix) } - pub fn img_attributes_up_to_480(&self, prefix: &str) -> ImgAttributes { + pub fn img_attributes_up_to_480(&self, base_name: &str, prefix: &str) -> ImgAttributes { let assets = match &self.max_320 { Some(max_320) => match &self.max_480 { Some(max_480) => vec![&self.max_160, max_320, max_480], @@ -113,10 +117,10 @@ impl PosterAssets { None => vec![&self.max_160] }; - ImgAttributes::new(assets, prefix) + ImgAttributes::new(assets, base_name, prefix) } - pub fn img_attributes_up_to_1280(&self, prefix: &str) -> ImgAttributes { + pub fn img_attributes_up_to_1280(&self, base_name: &str, prefix: &str) -> ImgAttributes { let mut assets = Vec::with_capacity(4); assets.push(&self.max_160); @@ -125,7 +129,7 @@ impl PosterAssets { if let Some(asset) = &self.max_800 { assets.push(asset); } if let Some(asset) = &self.max_1280 { assets.push(asset); } - ImgAttributes::new(assets, prefix) + ImgAttributes::new(assets, base_name, prefix) } pub fn largest(&self) -> &PosterAsset {