summaryrefslogtreecommitdiff
path: root/src/piece.rs
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2021-07-26 23:50:07 +0200
committerJulian T <julian@jtle.dk>2021-07-26 23:50:40 +0200
commitd7244c2cc7b8f62f2f42cca7f3dece89c30bf105 (patch)
tree8b7bae761350bc05e1db0cc338daffc947a8e745 /src/piece.rs
parent0ddf24fa0be620fc10cc07247b2c738b32943042 (diff)
Add scaled image to page
Diffstat (limited to 'src/piece.rs')
-rw-r--r--src/piece.rs15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/piece.rs b/src/piece.rs
index 2c0b545..1ebad66 100644
--- a/src/piece.rs
+++ b/src/piece.rs
@@ -1,4 +1,5 @@
use std::path::PathBuf;
+use std::collections::HashMap;
use crate::picture::{Picture, ConversionError};
use crate::context::Context;
use tera::Context as WebContext;
@@ -8,14 +9,14 @@ use serde::Serialize;
pub struct Piece {
pic: Picture,
- scaled_path: PathBuf,
- //thumb_path: PathBuf,
+ scaled: HashMap<String, PathBuf>,
info: Option<String>,
}
pub fn create_index(ctx: &Context, pieces: &[Piece]) -> Result<(), tera::Error> {
let mut web_ctx = WebContext::new();
web_ctx.insert("pieces", pieces);
+ web_ctx.insert("opts", &ctx.options);
println!("render: {}", ctx.tmpl.render("index.html", &web_ctx)?);
Ok(())
@@ -25,15 +26,19 @@ impl Piece {
pub fn new(ctx: &Context, pic: Picture) -> Result<Self, ConversionError> {
println!("Creating piece from file {}", pic.path.display());
let mut conv = pic.convert()?;
- let scaled_path = conv.get_size(ctx, ctx.options.size_scaled)?;
- //let thumb_path = conv.get_size(ctx, ctx.options.size_thumb)?;
+ let mut scaled = HashMap::with_capacity(ctx.config.sizes.capacity());
+
+ // Create all needed sizes
+ for (id, size) in ctx.config.sizes.iter() {
+ scaled.insert(id.clone(), conv.get_size(ctx, *size)?);
+ }
let info: Option<String> = pic.path.file_name()
.map(|name| name.to_str()).flatten()
.map(|name| ctx.config.info.get(name).map(|s| s.clone())).flatten();
Ok(Piece {
- pic, scaled_path, info,
+ pic, scaled, info,
})
}
}