From bc3e25f8c1edbd233ed0c266c574892e88644d9c Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Wed, 15 Jan 2025 15:54:27 +1300 Subject: Implement image galleries Each gallery image must be kept in the three directories images/large, images/small, and images/thumb. A gallery is a fragment with the language 'gallery' containing a list of image filenames, one per line. --- src/collect_files.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/collect_files.rs') diff --git a/src/collect_files.rs b/src/collect_files.rs index b0e24ed..cf39ebe 100644 --- a/src/collect_files.rs +++ b/src/collect_files.rs @@ -121,6 +121,15 @@ impl Website { // Process each entry. if entry.is_directory() { if let Some(stripped) = entry.name.strip_prefix("!") { + // Track all files inside the static directory. + for child in traverse_directory(&entry).unwrap() { + let source_path = child.original_path; + let relative_path = source_path.strip_prefix(&entry.original_path).unwrap_or_else( + |_| error!("Path doesn't start with {prefix:?}: {source_path:?}")) + .as_os_str().to_string_lossy().to_string(); + let full_url = format!("{stripped}/{relative_path}"); + self.static_files.push(StaticItem { full_url, source_path }) + } let full_url = make_url_safe(stripped); self.static_dirs.push(StaticItem { full_url, source_path }); } else { @@ -299,6 +308,11 @@ 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 get_config(&self, key: &str) -> String { self.config.get(key).map(String::to_owned).unwrap_or_else(String::new) } -- cgit v1.2.3-70-g09d2