add a basic generate() test
This commit is contained in:
parent
e605ba84e5
commit
5f2490ff0c
8 changed files with 244 additions and 25 deletions
|
|
@ -1,19 +1,23 @@
|
|||
use anyhow::Context;
|
||||
use serde::Deserialize;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Deserialize, Debug, PartialEq)]
|
||||
#[serde(default)]
|
||||
struct Config {
|
||||
thumbnail_size: (u32, u32),
|
||||
view_size: (u32, u32),
|
||||
output_dir: PathBuf,
|
||||
pub struct Config {
|
||||
pub thumbnail_size: (u32, u32),
|
||||
pub view_size: (u32, u32),
|
||||
pub output_dir: PathBuf,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
fn from_album(path: PathBuf) -> anyhow::Result<Config> {
|
||||
let content = fs::read(path.join("photojawn.conf.yml"))?;
|
||||
let cfg = serde_yml::from_slice(&content)?;
|
||||
pub fn from_album(path: PathBuf) -> anyhow::Result<Config> {
|
||||
let config_path = path.join("photojawn.conf.yml");
|
||||
let content = fs::read(&config_path)
|
||||
.with_context(|| format!("Failed to read config from {}", config_path.display()))?;
|
||||
let cfg = serde_yml::from_slice(&content)
|
||||
.with_context(|| format!("Failed to parse config from {}", config_path.display()))?;
|
||||
Ok(cfg)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,28 +1,27 @@
|
|||
mod album_dir;
|
||||
|
||||
use album_dir::AlbumDir;
|
||||
use crate::config::Config;
|
||||
pub use album_dir::AlbumDir;
|
||||
use std::env;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::path::PathBuf;
|
||||
|
||||
const OUTPUT_PATH: &'static str = "site";
|
||||
|
||||
pub fn generate(root_path: &PathBuf) -> anyhow::Result<()> {
|
||||
pub fn generate(root_path: &PathBuf) -> anyhow::Result<PathBuf> {
|
||||
let config = Config::from_album(root_path.to_path_buf())?;
|
||||
let orig_path = env::current_dir()?;
|
||||
let album = AlbumDir::try_from(root_path)?;
|
||||
env::set_current_dir(&root_path)?;
|
||||
|
||||
generate_images(&album)?;
|
||||
generate_html(&album)?;
|
||||
generate_images(&config, &album)?;
|
||||
generate_html(&config, &album)?;
|
||||
|
||||
env::set_current_dir(orig_path)?;
|
||||
Ok(root_path.join(config.output_dir))
|
||||
}
|
||||
|
||||
fn generate_images(config: &Config, album: &AlbumDir) -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn generate_images(album: &AlbumDir) -> anyhow::Result<()> {
|
||||
let output_path = album.path.join(OUTPUT_PATH);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn generate_html(album: &AlbumDir) -> anyhow::Result<()> {
|
||||
fn generate_html(config: &Config, album: &AlbumDir) -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ impl TryFrom<&PathBuf> for AlbumDir {
|
|||
let entry_path = entry?.path();
|
||||
|
||||
if entry_path.is_file() {
|
||||
println!("Found file: {}", entry_path.display());
|
||||
if let Some(filename) = entry_path.file_name() {
|
||||
if filename == "description.txt" {
|
||||
description = fs::read_to_string(entry_path)?;
|
||||
|
|
@ -65,8 +64,6 @@ impl TryFrom<&PathBuf> for AlbumDir {
|
|||
}
|
||||
}
|
||||
} else if entry_path.is_dir() {
|
||||
println!("Found dir: {}", entry_path.display());
|
||||
|
||||
if let Some(dirname) = entry_path.file_name().and_then(|n| n.to_str()) {
|
||||
if dirname.starts_with("_") {
|
||||
// Likely a templates or static dir
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ use photojawn::skel::make_skeleton;
|
|||
use std::path::Path;
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
env_logger::init();
|
||||
let cli = Cli::parse();
|
||||
|
||||
let album_path = Path::new(&cli.album_path);
|
||||
|
||||
match cli.subcommand {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue