making presentations use reveal_js.rs for getting slide_count

This commit is contained in:
Chris Cochrun 2023-09-29 11:45:13 -05:00
parent da361a55a7
commit 7dfb4caeaf
2 changed files with 20 additions and 11 deletions

View file

@ -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,

View file

@ -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