From dd0aff0b170a71ef2962fcd38b710c581d90f9da Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Fri, 12 Dec 2025 20:21:57 +1300 Subject: Allow using regular images in galleries Galleries previously required images to be placed in /images/large/.. and /images/thumb/.., but this was a chore if there was only a single average-quality version of the image to display. The path /images/.. is now used as a fallback if these more specialised paths do not exist. --- src/generate_html.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/generate_html.rs') diff --git a/src/generate_html.rs b/src/generate_html.rs index 306892b..2b979ea 100644 --- a/src/generate_html.rs +++ b/src/generate_html.rs @@ -257,27 +257,27 @@ pub fn document_to_html(page: &Page, website: &Website) -> String { html!(""); }, "gallery" => wrap!("div", "class='gallery'", for line in content.lines() { - let file = line.trim(); - if !website.has_image(file) { - warn!("Gallery on page {from:?} references nonexistent image {file:?}"); - continue; + let file_name = line.trim(); + if let Some(image_paths) = website.has_image(file_name, &root) { + let large = sanitize_text(&image_paths.large, false); + let thumb = sanitize_text(&image_paths.thumb, false); + html!(""); + } else { + warn!("Gallery on page {from:?} references nonexistent image {file_name:?}"); } - let large = sanitize_text(&format!("{root}images/large/{file}"), false); - // let small = sanitize_text(&format!("{root}images/small/{file}"), false); - let thumb = sanitize_text(&format!("{root}images/thumb/{file}"), false); - html!(""); }), "gallery-nav" => wrap!("div", "class='gallery-nav'", for line in content.lines() { let line = line.trim(); - if let Some((name, image)) = line.split_once("::") { + if let Some((name, file_name)) = line.split_once("::") { let name = name.trim(); - let image = image.trim(); + let file_name = file_name.trim(); let ParsedLink { path, class, label } = parse_internal_link(name, page, website); - if website.has_image(image) { - let thumb = sanitize_text(&format!("{root}images/thumb/{image}"), false); + if let Some(image_paths) = website.has_image(file_name, &root) { + let thumb = sanitize_text(&image_paths.thumb, false); html!("

{label}

") } else { - warn!("Gallery-nav on page {from:?} references nonexistent image {image:?}"); + warn!("Gallery on page {from:?} references nonexistent image {file_name:?}"); + warn!("Gallery-nav on page {from:?} references nonexistent image {file_name:?}"); } } else { warn!("Gallery-nav on page {from:?} has line without a '::' separator"); -- cgit v1.2.3-70-g09d2