From c3c69b160f4c5fd851fd1a49c01f633a56351f5d Mon Sep 17 00:00:00 2001 From: Julian T Date: Thu, 22 Jul 2021 21:36:15 +0200 Subject: Add smart image conversion --- src/context.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/context.rs') diff --git a/src/context.rs b/src/context.rs index 6bc4c05..55f3f97 100644 --- a/src/context.rs +++ b/src/context.rs @@ -14,6 +14,15 @@ pub struct Options { pub config: Option, #[structopt(help = "Picture location")] pub load: PathBuf, + #[structopt(short, long, default_value = "png", help = "Image extension to use for converted files")] + pub ext: String, + #[structopt(long, short, default_value = "build", help = "Where to build site")] + pub builddir: PathBuf, + + #[structopt(long, default_value = "1080", help = "Scaled size for image")] + pub size_scaled: u32, + #[structopt(long, default_value = "720", help = "Thumbnail size for image")] + pub size_thumb: u32, } #[derive(Debug)] @@ -36,16 +45,26 @@ pub struct Config { pub struct Context { pub options: Options, pub config: Config, + pub imgdir: PathBuf, } impl Context { pub fn new_with_args() -> Result { let opts = Options::from_args(); let config = Config::load_with_options(&opts)?; + let imgdir = opts.builddir.join("imgs"); + + // Create img dir + if let Err(err) = fs::create_dir(&imgdir) { + if err.kind() != io::ErrorKind::AlreadyExists { + return Err(ConfigError::from(err)); + } + } Ok(Context { options: opts, config: config, + imgdir: imgdir, }) } -- cgit v1.2.3