1use std::{
2 io::{self, Error},
3 path::PathBuf,
4};
5
6use html_ast_generator::HtmlElement;
7
8mod html_ast_generator;
9
10pub fn generate_presentation(path_folder: &PathBuf) -> Result<(String, Vec<PathBuf>), Error> {
12 let images_path_list = get_list_of_image_paths_sorted(path_folder)?;
15
16 let create_script_autonext = HtmlElement::create_script_autonext(
17 images_path_list
18 .iter()
19 .map(|i| i.file_name().unwrap().to_str().unwrap().to_string())
20 .collect(),
21 );
22 let child_body = vec![create_script_autonext];
23
24 let output: HtmlElement = HtmlElement::Node(String::from("body"), child_body);
25 Ok((output.generate_html().to_string(), images_path_list))
26}
27
28fn get_list_of_image_paths_sorted(path_folder: &PathBuf) -> Result<Vec<PathBuf>, Error> {
30 let mut images_path_list = path_folder
31 .read_dir()?
32 .map(|res| res.map(|e| e.path()))
33 .collect::<Result<Vec<_>, io::Error>>()?;
34 images_path_list.sort();
35 Ok(images_path_list)
36}