summaryrefslogtreecommitdiff
path: root/src/works
diff options
context:
space:
mode:
authorWriterV2 <primary-v2@protonmail.com>2023-04-02 14:56:30 +0200
committerWriterV2 <primary-v2@protonmail.com>2023-04-02 14:56:30 +0200
commit34771414b194798f020597f44ff4911c1efa3cd4 (patch)
tree6bb0f1c8d069d2f1fd22d9257a7ca4486f73e25b /src/works
parente5c4a7b348acf95bb9700d0dfac3f98ba5ed2742 (diff)
Add path helper methods for story
Diffstat (limited to 'src/works')
-rw-r--r--src/works/stories.rs18
1 files changed, 15 insertions, 3 deletions
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<String> {
- 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))
}
}