diff --git a/src/rust/lib.rs b/src/rust/lib.rs index b654d00..0ef9306 100644 --- a/src/rust/lib.rs +++ b/src/rust/lib.rs @@ -3,12 +3,13 @@ mod file_helper; pub mod image_model; pub mod models; pub mod presentation_model; -pub mod song_model; +pub mod reveal_js; pub mod schema; mod service_thing; mod settings; pub mod slide_model; mod slide_obj; +pub mod song_model; pub mod video_model; pub mod ytdl; // mod video_thumbnail; diff --git a/src/rust/presentation_model.rs b/src/rust/presentation_model.rs index 9febd83..ddcc6be 100644 --- a/src/rust/presentation_model.rs +++ b/src/rust/presentation_model.rs @@ -2,6 +2,7 @@ mod presentation_model { use crate::models::*; use crate::presentation_model::presentation_model::Presentation; + use crate::reveal_js; use crate::schema::presentations::dsl::*; use diesel::sqlite::SqliteConnection; use diesel::{delete, insert_into, prelude::*}; @@ -187,12 +188,18 @@ mod presentation_model { ) -> bool { let db = &mut self.as_mut().get_db(); // println!("{:?}", db); + let mut actual_page_count = new_page_count; + if presentation_html { + let actual_path = presentation_path.clone().to_string().trim(); + actual_page_count = reveal_js::count_slides_and_fragments(actual_path); + } + let presentation = self::Presentation { id: presentation_id, title: presentation_title.clone().to_string(), - html: false, + html: presentation_html, path: presentation_path.clone().to_string(), - page_count: new_page_count, + page_count: actual_page_count, }; println!("{:?}", presentation); diff --git a/src/rust/reveal_js.rs b/src/rust/reveal_js.rs new file mode 100644 index 0000000..5f5d4b1 --- /dev/null +++ b/src/rust/reveal_js.rs @@ -0,0 +1,41 @@ +// use dirs; +use std::fs::read_to_string; + +// struct Slide { +// num_fragments: usize, +// } + +// struct Presentation { +// num_slides: usize, +// num_fragments: usize, +// } + +pub fn count_slides_and_fragments(html_file_path: &str) -> i32 { + // Read the HTML file + let html_content = read_to_string(html_file_path).expect("Failed to read HTML file"); + + // Split HTML content by slide delimiters + let slide_delimiter = " = html_content.split(slide_delimiter).collect(); + + // Count slides and fragments + let num_slides = slide_content.len() - 1; + let mut num_fragments = 0; + + for slide_html in slide_content.iter().skip(1) { + let fragments = slide_html.matches("fragment").count(); + num_fragments += fragments; + } + + let total = num_slides + num_fragments; + + total as i32 +} + +// fn main() { +// let html_file_path = "path/to/presentation.html"; +// let presentation = count_slides_and_fragments(html_file_path); + +// println!("Total number of slides: {}", presentation.num_slides); +// println!("Total number of fragments: {}", presentation.num_fragments); +// }