use std::{
io::{self, Error},
path::PathBuf,
};
use html_ast_generator::HtmlElement;
mod html_ast_generator;
pub fn generate_presentation(path_folder: &PathBuf) -> Result<(String, Vec<PathBuf>), Error> {
let images_path_list = get_list_of_image_paths_sorted(path_folder)?;
let create_script_autonext = HtmlElement::create_script_autonext(
images_path_list
.iter()
.map(|i| i.file_name().unwrap().to_str().unwrap().to_string())
.collect(),
);
let child_body = vec![create_script_autonext];
let output: HtmlElement = HtmlElement::Node(String::from("body"), child_body);
Ok((output.generate_html().to_string(), images_path_list))
}
fn get_list_of_image_paths_sorted(path_folder: &PathBuf) -> Result<Vec<PathBuf>, Error> {
let mut images_path_list = path_folder
.read_dir()?
.map(|res| res.map(|e| e.path()))
.collect::<Result<Vec<_>, io::Error>>()?;
images_path_list.sort();
Ok(images_path_list)
}