Some fixes

- Render markdown descriptions
- Don't include the cover in the album's images, but make sure we
  generate a thumbnail for it
- Make extra sure we don't include slides dirs
This commit is contained in:
Nick Pegg 2025-05-07 14:27:11 -07:00
parent 890b46e45d
commit 584ec41c7a
5 changed files with 72 additions and 7 deletions

View file

@ -79,6 +79,7 @@ impl TryFrom<&AlbumDir> for AlbumContext {
};
// Pick a cover image thumbnail and build a path to it
// TODO: If album has no images, pick the cover from one of the albums
let cover_thumbnail_path = match &album.cover {
Some(i) => Path::new("slides").join(&i.thumb_filename),
None => PathBuf::from(""),
@ -147,12 +148,20 @@ fn copy_static(config: &Config) -> anyhow::Result<()> {
fn generate_images(config: &Config, album: &AlbumDir) -> anyhow::Result<()> {
let output_path = album.path.join(&config.output_dir);
// TODO: progress bar ?
let all_images: Vec<&Image> = album.iter_all_images().collect();
let mut all_images: Vec<&Image> = album.iter_all_images().collect();
// also resize cover image
if let Some(cover) = &album.cover {
all_images.push(cover);
}
all_images.par_iter().try_for_each(|img| {
let orig_image = image::open(&img.path)?;
// TODO: If orig_path is the same as the original image, and quick mode is on, skip to next
// image
//
// TODO: Hard-link if it's supported, to save on hard drive space
let orig_path = output_path.join(&img.path);
log::info!(
"Copying original {} -> {}",

View file

@ -40,15 +40,19 @@ impl AlbumDir {
if filename == "description.txt" {
description = fs::read_to_string(entry_path)?;
} else if filename == "description.md" {
let _conents = fs::read_to_string(entry_path)?;
// TODO: render markdown
todo!();
log::debug!("Loading Markdown from {}", entry_path.display());
let mut description = String::new();
let contents = fs::read_to_string(&entry_path)?;
let parser = pulldown_cmark::Parser::new(&contents);
pulldown_cmark::html::push_html(&mut description, parser);
} else {
if filename.to_string_lossy().starts_with("cover") {
cover = Some(Image::new(
entry_path.strip_prefix(root)?.to_path_buf(),
String::new(),
)?);
// Don't include the cover in the set of images
continue;
}
let reader = ImageReader::open(&entry_path)?.with_guessed_format()?;
@ -60,9 +64,15 @@ impl AlbumDir {
if entry_path.with_extension("txt").exists() {
description = fs::read_to_string(entry_path.with_extension("txt"))?;
} else if entry_path.with_extension("md").exists() {
let _contents = fs::read(entry_path.with_extension("md"))?;
// TODO: render markdown
todo!();
log::debug!(
"Loading Markdown from {}",
entry_path.with_extension("md").display()
);
let mut description = String::new();
let contents =
fs::read_to_string(&entry_path.with_extension("md"))?;
let parser = pulldown_cmark::Parser::new(&contents);
pulldown_cmark::html::push_html(&mut description, parser);
}
images.push(Image::new(
@ -80,6 +90,8 @@ impl AlbumDir {
} else if dirname == "site" {
// Is a generated site dir, don't descend into it
continue;
} else if dirname == "slides" {
continue;
}
children.push(AlbumDir::from_path(&entry_path, root)?);
@ -90,6 +102,7 @@ impl AlbumDir {
if cover.is_none() && !images.is_empty() {
cover = Some(images[0].clone());
}
// TODO: sort children and albums alphabetically
Ok(AlbumDir {
path: p.strip_prefix(root)?.to_path_buf(),

View file

@ -6,6 +6,7 @@ use std::path::Path;
fn main() -> anyhow::Result<()> {
env_logger::init();
let cli = Cli::parse();
// TODO: canonicalize path? To allow ~/foo/bar
let album_path = Path::new(&cli.album_path);
match cli.subcommand {