From 001650a656772018c005a1ce9807663adfc6c07a Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Mon, 20 Oct 2025 14:59:37 -0500 Subject: [PATCH 1/2] presentations can show only the slides in their index ranges This means that we only generate slides for these indexes. --- src/core/presentations.rs | 48 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/src/core/presentations.rs b/src/core/presentations.rs index 174d5eb..b3c4a35 100644 --- a/src/core/presentations.rs +++ b/src/core/presentations.rs @@ -186,6 +186,15 @@ impl ServiceTrait for Presentation { fn to_slides(&self) -> Result> { debug!(?self); + let PresKind::Pdf { + starting_index, + ending_index, + } = self.kind + else { + return Err(miette::miette!( + "This is not a pdf presentation" + )); + }; let background = Background::try_from(self.path.clone()) .into_diagnostic()?; debug!(?background); @@ -219,6 +228,12 @@ impl ServiceTrait for Presentation { let mut slides: Vec = vec![]; for (index, page) in pages.into_iter().enumerate() { + if (index as i32) < starting_index { + continue; + } else if (index as i32) > ending_index { + continue; + }; + let slide = SlideBuilder::new() .background( Background::try_from(self.path.clone()) @@ -307,7 +322,7 @@ impl Model { let _ = self.add_item(Presentation { id: presentation.id, title: presentation.title, - path: presentation.path.into(), + path: presentation.path.clone().into(), kind: if presentation.html { PresKind::Html } else { @@ -324,7 +339,28 @@ impl Model { ending_index: ending_index as i32, } } else { - PresKind::Generic + let path = + PathBuf::from(presentation.path); + if let Ok(document) = + Document::open(path.as_path()) + { + if let Ok(count) = + document.page_count() + { + let ending_index = count - 1; + PresKind::Pdf { + starting_index: 0, + ending_index, + } + } else { + PresKind::Pdf { + starting_index: 0, + ending_index: 0, + } + } + } else { + PresKind::Generic + } } }, }); @@ -485,7 +521,13 @@ mod test { #[test] pub fn test_pres() { let pres = Presentation::new(); - assert_eq!(pres.get_kind(), &PresKind::Pdf) + assert_eq!( + pres.get_kind(), + &PresKind::Pdf { + starting_index: 0, + ending_index: 0, + } + ) } #[tokio::test] From 3c1c76d41ce0b828da651831af9aa0359014484b Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Mon, 20 Oct 2025 15:02:00 -0500 Subject: [PATCH 2/2] presentations don't need to create the slide at all if not in range --- src/core/presentations.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/core/presentations.rs b/src/core/presentations.rs index b3c4a35..09030fb 100644 --- a/src/core/presentations.rs +++ b/src/core/presentations.rs @@ -204,7 +204,14 @@ impl ServiceTrait for Presentation { let pages = document.pages().into_diagnostic()?; debug!(?pages); let pages: Vec = pages - .filter_map(|page| { + .enumerate() + .filter_map(|(index, page)| { + if (index as i32) < starting_index { + return None; + } else if (index as i32) > ending_index { + return None; + }; + let Some(page) = page.ok() else { return None; }; @@ -227,13 +234,7 @@ impl ServiceTrait for Presentation { .collect(); let mut slides: Vec = vec![]; - for (index, page) in pages.into_iter().enumerate() { - if (index as i32) < starting_index { - continue; - } else if (index as i32) > ending_index { - continue; - }; - + for (index, page) in pages.into_iter() { let slide = SlideBuilder::new() .background( Background::try_from(self.path.clone())