From deda52fe10fffe5eb4701566c5b0ada5402c675d Mon Sep 17 00:00:00 2001 From: WriterV2 Date: Fri, 10 Feb 2023 23:01:27 +0100 Subject: Add story helper functions --- src/works/stories.rs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'src/works') 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 { + 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 { + Ok(format!( + "docs/stories/{}.html", + self.path_to_document.replace(".pdf", "") + )) + } +} + // language of story content #[derive(Deserialize, Serialize, Debug)] pub enum Language { -- cgit v1.2.3