summaryrefslogtreecommitdiff
path: root/src/piece.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/piece.rs')
-rw-r--r--src/piece.rs25
1 files changed, 21 insertions, 4 deletions
diff --git a/src/piece.rs b/src/piece.rs
index a0cc18e..2c0b545 100644
--- a/src/piece.rs
+++ b/src/piece.rs
@@ -1,22 +1,39 @@
use std::path::PathBuf;
use crate::picture::{Picture, ConversionError};
use crate::context::Context;
+use tera::Context as WebContext;
+use serde::Serialize;
-#[derive(Debug)]
+#[derive(Debug, Serialize)]
pub struct Piece {
pic: Picture,
+
scaled_path: PathBuf,
- thumb_path: PathBuf,
+ //thumb_path: 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);
+
+ println!("render: {}", ctx.tmpl.render("index.html", &web_ctx)?);
+ Ok(())
}
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 thumb_path = conv.get_size(ctx, ctx.options.size_thumb)?;
+
+ 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, thumb_path,
+ pic, scaled_path, info,
})
}
}