From 34771414b194798f020597f44ff4911c1efa3cd4 Mon Sep 17 00:00:00 2001 From: WriterV2 Date: Sun, 2 Apr 2023 14:56:30 +0200 Subject: Add path helper methods for story --- src/works/stories.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src/works') diff --git a/src/works/stories.rs b/src/works/stories.rs index a38a7c0..9db3ec3 100644 --- a/src/works/stories.rs +++ b/src/works/stories.rs @@ -49,7 +49,7 @@ impl Story { // HTML file doesn't exist yet !std::path::Path::new(&self.get_html_path()).exists() // pdf document changes - || std::fs::metadata(format!("docs/stories/{}", &self.path_to_document))?.modified()? + || std::fs::metadata(self.get_pdf_path())?.modified()? > std::fs::metadata(self.get_html_path())?.modified()? // base template changes || std::fs::metadata("templates/base.html")?.modified()? @@ -69,10 +69,22 @@ impl Story { ) } + // get path to pdf document + fn get_pdf_path(&self) -> String { + format!("docs/stories/{}", &self.path_to_document) + } + + // get path to html file with story content + fn get_content_html_path(&self) -> String { + format!( + "stories_html/{}.html", + self.path_to_document.replace(".pdf", "") + ) + } + // extract text from pdf document fn get_text(&self) -> anyhow::Result { - let text = std::fs::read_to_string(format!("stories_html/{}.html", self.path_to_document.replace(".pdf", "")))?; - + let text = std::fs::read_to_string(self.get_content_html_path())?; anyhow::Ok(text).with_context(|| format!("Failed to extract text for {}", self.title)) } } -- cgit v1.2.3