diff options
| -rw-r--r-- | docs/stories.html | 28 | ||||
| -rw-r--r-- | src/works/stories.rs | 21 | ||||
| -rw-r--r-- | stories.json | 9 |
3 files changed, 38 insertions, 20 deletions
diff --git a/docs/stories.html b/docs/stories.html index 4d3894f..f724dd3 100644 --- a/docs/stories.html +++ b/docs/stories.html @@ -39,18 +39,6 @@ Despite my linguistic difficulties to express myself, my love for story telling </div> <div class="works"> - <a href="./stories/the_fallen_dragons_of_bavaria.html" class="work-card card"> - <div class="title-and-description"> - <h3>The fallen dragons of Bavaria</h3> - <p>In his new life in Germany Kazuyuki is needed by dragons.</p> - </div> - <div class="info"> - <span>3 Pages</span> - <span class="story-language">English</span> - <span>Last Update: 2023-04-02</span> - </div> - </a> - <a href="./stories/das_schweigende_spiegelbild.html" class="work-card card"> <div class="title-and-description"> <h3>Das schweigende Spiegelbild</h3> @@ -59,7 +47,7 @@ Despite my linguistic difficulties to express myself, my love for story telling <div class="info"> <span>2 Pages</span> <span class="story-language">German</span> - <span>Last Update: 2023-01-28</span> + <span>Last Update: 2023-04-10</span> </div> </a> @@ -71,7 +59,19 @@ Despite my linguistic difficulties to express myself, my love for story telling <div class="info"> <span>7 Pages</span> <span class="story-language">German</span> - <span>Last Update: 2023-01-28</span> + <span>Last Update: 2023-04-10</span> + </div> + </a> + + <a href="./stories/the_fallen_dragons_of_bavaria.html" class="work-card card"> + <div class="title-and-description"> + <h3>The fallen dragons of Bavaria</h3> + <p>In his new life in Germany Kazuyuki is needed by dragons.</p> + </div> + <div class="info"> + <span>3 Pages</span> + <span class="story-language">English</span> + <span>Last Update: 2023-04-02</span> </div> </a> diff --git a/src/works/stories.rs b/src/works/stories.rs index 9db3ec3..c2b4b8f 100644 --- a/src/works/stories.rs +++ b/src/works/stories.rs @@ -15,6 +15,7 @@ struct Story { path_to_document: String, number_of_pages: u16, language: Language, + #[serde(default)] last_update: NaiveDate, } @@ -40,6 +41,16 @@ impl super::Works for Stories { } anyhow::Ok(()).with_context(|| "Failed to render single story pages") } + + // create stories from stories.json and add last modification date + fn new_from_file(file: std::fs::File) -> anyhow::Result<Self> { + let mut stories: Stories = serde_json::from_reader(std::io::BufReader::new(&file))?; + for story in stories.0.iter_mut() { + story.get_last_modified()?; + } + // add error context + Ok(stories) + } } impl Story { @@ -87,6 +98,16 @@ impl Story { 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)) } + + // get date of last modification of pdf file + fn get_last_modified(&mut self) -> anyhow::Result<chrono::NaiveDate> { + use std::os::linux::fs::MetadataExt; + let pdf_last_modification = std::fs::metadata(self.get_pdf_path())?.st_mtime(); + let html_last_modification = std::fs::metadata(self.get_html_path())?.st_mtime(); + let date = chrono::NaiveDateTime::from_timestamp(std::cmp::max(pdf_last_modification, html_last_modification), 0).date(); + self.last_update = date; + Ok(date) + } } // language of story content diff --git a/stories.json b/stories.json index 2fec76b..e9b10a9 100644 --- a/stories.json +++ b/stories.json @@ -4,23 +4,20 @@ "description": "Der gefährliche Zauber von Leon wird von seinem wegweisenden Freund durchschaut. Kann er ihn stoppen?", "path_to_document": "mit_gutem_gewissen.pdf", "number_of_pages": 7, - "language": "German", - "last_update": "2023-01-28" + "language": "German" }, { "title": "Das schweigende Spiegelbild", "description": "Das Spiegelbild verzweifelt in seiner Hilflosigkeit gegenüber seinem Ich.", "path_to_document": "das_schweigende_spiegelbild.pdf", "number_of_pages": 2, - "language": "German", - "last_update": "2023-01-28" + "language": "German" }, { "title": "The fallen dragons of Bavaria", "description": "In his new life in Germany Kazuyuki is needed by dragons.", "path_to_document": "the_fallen_dragons_of_bavaria.pdf", "number_of_pages": 3, - "language": "English", - "last_update": "2023-04-02" + "language": "English" } ] |
