summaryrefslogtreecommitdiff
path: root/src/works/stories.rs
diff options
context:
space:
mode:
authorWriterV2 <primary-v2@protonmail.com>2023-02-11 22:13:23 +0100
committerWriterV2 <primary-v2@protonmail.com>2023-02-11 22:13:23 +0100
commit1141c35800b0298b632b98db09a5379f2ff88b3d (patch)
tree595fceed2f030afdf3e5a052d88b1985c160d3ed /src/works/stories.rs
parentcc4210ab78cd0cfcd53cf793c82b58009d1c7bb9 (diff)
Change story document modified function to more general update available function
Diffstat (limited to 'src/works/stories.rs')
-rw-r--r--src/works/stories.rs16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/works/stories.rs b/src/works/stories.rs
index 092b721..4bd492b 100644
--- a/src/works/stories.rs
+++ b/src/works/stories.rs
@@ -27,7 +27,7 @@ impl super::Works for Stories {
) -> anyhow::Result<()> {
let mut result = Vec::new();
for story in self.0.iter() {
- if story.document_modified()? {
+ if story.update_available()? {
let mut context = tera::Context::new();
context.insert("story", story);
context.insert("text", &story.get_text()?);
@@ -42,11 +42,19 @@ impl super::Works for Stories {
}
impl Story {
- // check if story document was modified
- fn document_modified(&self) -> anyhow::Result<bool> {
+ // check if it's necessary to re-compile the html single page
+ fn update_available(&self) -> anyhow::Result<bool> {
Ok(
+ // pdf document changes
std::fs::metadata(format!("docs/stories/{}", &self.path_to_document))?.modified()?
- > std::fs::metadata(self.get_html_path()?)?.modified()?,
+ > std::fs::metadata(self.get_html_path()?)?.modified()?
+ // base template changes
+ || std::fs::metadata("templates/base.html")?.modified()?
+ > std::fs::metadata(self.get_html_path()?)?.modified()?
+ // story template changes
+ ||std::fs::metadata("templates/story.html")?.modified()? > std::fs::metadata(self.get_html_path()?)?.modified()?
+ // HTML file doesn't exist yet
+ || !std::path::Path::new(&self.get_html_path()?).exists(),
)
}