fix breadcrumbs, include images in albums

This commit is contained in:
Nick Pegg 2025-05-06 20:51:26 -07:00
parent a58878711b
commit 141ea6dc5d
4 changed files with 24 additions and 17 deletions

View file

@ -4,9 +4,9 @@
{% if root_path %} {% if root_path %}
<h1> <h1>
{% for crumb in breadcrumbs %} {% for crumb in breadcrumbs %}
/ <a href="{{crumb.path}}">{{crumb.name}}</a> <a href="{{crumb.path}}">{{crumb.name}}</a> /
{% endfor %} {% endfor %}
/ {{name}} {{name}}
</h1> </h1>
<hr> <hr>
{% endif %} {% endif %}
@ -35,12 +35,12 @@
{% endfor %} {% endfor %}
</div> </div>
{% endif %} {% endif %}
{% if album_dir.images %} {% if images %}
{% if children %} {% if children %}
<h2>Photos</h2> <h2>Photos</h2>
{% endif %} {% endif %}
<div id="album-photos"> <div id="album-photos">
{% for image in album_dir.images %} {% for image in images %}
<div class="thumbnail"> <div class="thumbnail">
<a href="slides/{{image.html_filename}}"> <a href="slides/{{image.html_filename}}">
<img src="slides/{{image.thumb_filename}}" /> <img src="slides/{{image.thumb_filename}}" />

View file

@ -1 +1 @@
moon.jpg mountains.jpg

View file

@ -29,7 +29,7 @@ struct AlbumContext {
name: String, name: String,
description: String, description: String,
// TODO: images images: Vec<Image>,
// Path to the cover image thumbnail within /slides/, relative to the album dir. Used when // Path to the cover image thumbnail within /slides/, relative to the album dir. Used when
// linking to an album from a parent album // linking to an album from a parent album
@ -88,12 +88,14 @@ impl TryFrom<&AlbumDir> for AlbumContext {
.iter() .iter()
.map(|a| AlbumContext::try_from(a)) .map(|a| AlbumContext::try_from(a))
.collect::<anyhow::Result<Vec<AlbumContext>>>()?; .collect::<anyhow::Result<Vec<AlbumContext>>>()?;
let images: Vec<Image> = album.images.clone();
Ok(AlbumContext { Ok(AlbumContext {
root_path,
name, name,
description: album.description.clone(), description: album.description.clone(),
breadcrumbs, breadcrumbs,
root_path, images,
children, children,
cover_thumbnail_path, cover_thumbnail_path,
}) })

View file

@ -1,7 +1,7 @@
use anyhow::anyhow; use anyhow::anyhow;
use image::ImageReader; use image::ImageReader;
use serde::Serialize; use serde::Serialize;
use std::ffi::{OsStr, OsString}; use std::ffi::OsString;
use std::fs; use std::fs;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::slice::Iter; use std::slice::Iter;
@ -152,16 +152,16 @@ impl<'a> Iterator for AlbumIter<'a> {
pub struct Image { pub struct Image {
/// Path to the image, relative to the root album /// Path to the image, relative to the root album
pub path: PathBuf, pub path: PathBuf,
pub filename: OsString, pub filename: String,
/// Text description of the image which is displayed below it on the HTML page /// Text description of the image which is displayed below it on the HTML page
pub description: String, pub description: String,
pub thumb_filename: OsString, pub thumb_filename: String,
pub thumb_path: PathBuf, pub thumb_path: PathBuf,
pub screen_filename: OsString, pub screen_filename: String,
pub screen_path: PathBuf, pub screen_path: PathBuf,
pub html_filename: OsString, pub html_filename: String,
pub html_path: PathBuf, pub html_path: PathBuf,
} }
@ -173,7 +173,9 @@ impl Image {
"Image path {} is missing a filename", "Image path {} is missing a filename",
path.display() path.display()
))? ))?
.into(); .to_str()
.ok_or(anyhow!("Cannot convert {} to a string", path.display()))?
.to_string();
let thumb_filename = Self::slide_filename(&path, "thumb", true)?; let thumb_filename = Self::slide_filename(&path, "thumb", true)?;
let thumb_path = Self::slide_path(&path, &thumb_filename); let thumb_path = Self::slide_path(&path, &thumb_filename);
let screen_filename = Self::slide_filename(&path, "screen", true)?; let screen_filename = Self::slide_filename(&path, "screen", true)?;
@ -198,7 +200,7 @@ impl Image {
/// Returns the filename for a given slide type. For example if ext = "thumb" and the current /// Returns the filename for a given slide type. For example if ext = "thumb" and the current
/// filename is "blah.jpg" this will return "blah.thumb.jpg". If keep_ext if false, it would /// filename is "blah.jpg" this will return "blah.thumb.jpg". If keep_ext if false, it would
/// return "blah.thumb" /// return "blah.thumb"
fn slide_filename(path: &PathBuf, ext: &str, keep_ext: bool) -> anyhow::Result<OsString> { fn slide_filename(path: &PathBuf, ext: &str, keep_ext: bool) -> anyhow::Result<String> {
let mut new_ext: OsString = ext.into(); let mut new_ext: OsString = ext.into();
if keep_ext { if keep_ext {
if let Some(e) = path.extension() { if let Some(e) = path.extension() {
@ -216,13 +218,16 @@ impl Image {
let new_path = path.with_extension(new_ext); let new_path = path.with_extension(new_ext);
let new_name = new_path let new_name = new_path
.file_name() .file_name()
.ok_or(anyhow!("Image {} missing a file name", path.display()))?; .ok_or(anyhow!("Image {} missing a file name", path.display()))?
.to_str()
.ok_or(anyhow!("Unable to convert {} to a string", path.display()))?
.to_string();
Ok(new_name.into()) Ok(new_name)
} }
/// Returns the path to the file in the slides dir given the path to the original image /// Returns the path to the file in the slides dir given the path to the original image
fn slide_path(path: &PathBuf, file_name: &OsStr) -> PathBuf { fn slide_path(path: &PathBuf, file_name: &str) -> PathBuf {
let mut new_path = path.clone(); let mut new_path = path.clone();
new_path.pop(); new_path.pop();
new_path.push("slides"); new_path.push("slides");