From 7dfb4caeaf93273ecba8edc98ce8522a5079b852 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Fri, 29 Sep 2023 11:45:13 -0500 Subject: [PATCH] making presentations use reveal_js.rs for getting slide_count --- src/rust/presentation_model.rs | 18 ++++++++++++------ src/rust/reveal_js.rs | 13 ++++++++----- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/rust/presentation_model.rs b/src/rust/presentation_model.rs index ac8cead..50fc3ab 100644 --- a/src/rust/presentation_model.rs +++ b/src/rust/presentation_model.rs @@ -8,6 +8,7 @@ mod presentation_model { use diesel::{delete, insert_into, prelude::*, update}; // use sqlx::Connection; use std::path::{Path, PathBuf}; + use tracing::{debug, debug_span, error, info, instrument}; unsafe extern "C++" { include!(< QAbstractListModel >); @@ -191,9 +192,9 @@ mod presentation_model { let presentation_id = self.rust().highest_id + 1; let presentation_title = QString::from(name); let presentation_path = url.to_qstring(); - println!("{:?}", file_path.extension().unwrap()); - let presentation_html = file_path.extension().unwrap() - == std::ffi::OsStr::new(".html"); + let presentation_html = + file_path.extension().unwrap() == "html"; + debug!(html = presentation_html, ?file_path, extension = ?file_path.extension()); if self.as_mut().add_item( presentation_id, @@ -222,13 +223,18 @@ mod presentation_model { // println!("{:?}", db); let mut actual_page_count = new_page_count; if presentation_html { - let actual_path = - presentation_path.clone().to_string(); + let actual_path = PathBuf::from( + presentation_path.clone().to_string(), + ); actual_page_count = reveal_js::count_slides_and_fragments( - actual_path.trim(), + &actual_path, ); } + debug!( + page_count = actual_page_count, + html = presentation_html + ); let presentation = self::Presentation { id: presentation_id, diff --git a/src/rust/reveal_js.rs b/src/rust/reveal_js.rs index 6479d15..876671a 100644 --- a/src/rust/reveal_js.rs +++ b/src/rust/reveal_js.rs @@ -1,7 +1,9 @@ // use dirs; -use std::fs::read_to_string; +use std::{fs::read_to_string, path::Path}; +use tracing::{debug, debug_span, error, info, instrument}; -pub fn count_slides_and_fragments(html_file_path: &str) -> i32 { +pub fn count_slides_and_fragments(html_file_path: Path) -> i32 { + debug!("Starting slide counter"); // Read the HTML file let html_content = read_to_string(html_file_path) .expect("Failed to read HTML file"); @@ -21,9 +23,10 @@ pub fn count_slides_and_fragments(html_file_path: &str) -> i32 { } let total = num_slides + num_fragments; - println!( - "SLIDE_NUMBERS: slides: {:?}, fragments: {:?}, total: {:?}", - num_slides, num_fragments, total + debug!( + slides = num_slides, + fragments = num_fragments, + total = total ); total as i32