summaryrefslogtreecommitdiff
path: root/src/context.rs
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2021-07-22 21:36:15 +0200
committerJulian T <julian@jtle.dk>2021-07-22 21:36:15 +0200
commitc3c69b160f4c5fd851fd1a49c01f633a56351f5d (patch)
tree55cdca5f052717d1c7f9abab97e864f28dc17534 /src/context.rs
parent69bbd4ed3804833b15285cf8637e96e59135f223 (diff)
Add smart image conversion
Diffstat (limited to 'src/context.rs')
-rw-r--r--src/context.rs19
1 files changed, 19 insertions, 0 deletions
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<PathBuf>,
#[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<Context, ConfigError> {
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,
})
}