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/collect_files.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src/collect_files.rs') diff --git a/src/collect_files.rs b/src/collect_files.rs index 30dcb98..e3d3a11 100644 --- a/src/collect_files.rs +++ b/src/collect_files.rs @@ -75,6 +75,11 @@ pub struct Highlighters { pub highlighters: Vec, } +pub struct ImagePaths { + pub thumb: String, + pub large: String, +} + impl Page { pub fn root(&self) -> String { let mut root = String::new(); @@ -408,9 +413,22 @@ impl Website { return None; } - pub fn has_image(&self, file_name: &str) -> bool { - let image_path = format!("images/thumb/{file_name}"); - self.static_files.iter().any(|s| s.full_url == image_path) + pub fn has_image(&self, file_name: &str, root: &str) -> Option { + let check = |path: String| + match self.static_files.iter().any(|s| s.full_url == path) { + true => Some(format!("{root}{path}")), + false => None, + }; + let thumb_path = check(format!("images/thumb/{file_name}")); + let large_path = check(format!("images/large/{file_name}")); + let fallback_path = check(format!("images/{file_name}")) + .or(large_path.clone()) + .or(thumb_path.clone()); + + Some(ImagePaths { + thumb: thumb_path.or(fallback_path.clone())?, + large: large_path.or(fallback_path.clone())?, + }) } pub fn get_config(&self, key: &str) -> String { -- cgit v1.2.3-70-g09d2