diff options
| author | WriterV2 <primary-v2@protonmail.com> | 2023-02-10 23:01:27 +0100 |
|---|---|---|
| committer | WriterV2 <primary-v2@protonmail.com> | 2023-02-10 23:01:27 +0100 |
| commit | deda52fe10fffe5eb4701566c5b0ada5402c675d (patch) | |
| tree | da1e293a318925b1505dce3cbce3caa19026c7db /src | |
| parent | b24db0321b68853f5c062b3e1a710a12f549bbd6 (diff) | |
Add story helper functions
Diffstat (limited to 'src')
| -rw-r--r-- | src/works/stories.rs | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/works/stories.rs b/src/works/stories.rs index ccc01e0..22ad1dc 100644 --- a/src/works/stories.rs +++ b/src/works/stories.rs @@ -31,13 +31,7 @@ impl super::Works for Stories { let mut context = tera::Context::new(); context.insert("story", story); result.push(std::fs::write( - format!( - // use story document name for the single page - // e.g. mit_gutem_gewissen.pdf -> mit_gutem_gewissen.html - "docs/stories/{}.html", - story.path_to_document.replace(".pdf", "") - ) - .as_str(), + story.get_html_path()?.as_str(), tera_instance.render(format!("{}.html", template_name).as_str(), &context)?, )); } @@ -45,6 +39,25 @@ impl super::Works for Stories { } } +impl Story { + // check if story document was modified + fn document_modified(&self) -> anyhow::Result<bool> { + Ok( + std::fs::metadata(format!("docs/stories/{}", &self.path_to_document))?.modified()? + > std::fs::metadata(self.get_html_path()?)?.modified()?, + ) + } + + // use story document name for the single page + // e.g. mit_gutem_gewissen.pdf -> mit_gutem_gewissen.html + fn get_html_path(&self) -> anyhow::Result<String> { + Ok(format!( + "docs/stories/{}.html", + self.path_to_document.replace(".pdf", "") + )) + } +} + // language of story content #[derive(Deserialize, Serialize, Debug)] pub enum Language { |
