summaryrefslogtreecommitdiff
path: root/src/collect_files.rs
diff options
context:
space:
mode:
authorBen Bridle <ben@derelict.engineering>2025-12-12 20:21:57 +1300
committerBen Bridle <ben@derelict.engineering>2025-12-12 20:22:08 +1300
commitdd0aff0b170a71ef2962fcd38b710c581d90f9da (patch)
treecf969477d6209cad053821b0aaf7ab9e1b930190 /src/collect_files.rs
parent50df287852367d3e50779155c6e92b6e2a388c9d (diff)
downloadtoaster-dd0aff0b170a71ef2962fcd38b710c581d90f9da.zip
Allow using regular images in galleriesHEADmain
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.
Diffstat (limited to 'src/collect_files.rs')
-rw-r--r--src/collect_files.rs24
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 {