diff options
Diffstat (limited to 'src/collect_files.rs')
| -rw-r--r-- | src/collect_files.rs | 24 |
1 files changed, 21 insertions, 3 deletions
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<Highlighter>, } +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<ImagePaths> { + 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 { |
