From 00d9bb0e50ee04f3de5a98bf0885640797a55296 Mon Sep 17 00:00:00 2001 From: WriterV2 Date: Fri, 10 Feb 2023 20:39:34 +0100 Subject: Add pages for every story --- Cargo.toml | 1 + docs/index.html | 2 +- docs/stories.html | 6 ++--- docs/stories/das_schweigende_spiegelbild.html | 34 ++++++++++++++++++++++++++ docs/stories/mit_gutem_gewissen.html | 34 ++++++++++++++++++++++++++ src/works/stories.rs | 35 ++++++++++++++++++++------- stories.json | 4 +-- templates/base.html | 2 +- templates/stories.html | 2 +- templates/story.html | 6 +++++ 10 files changed, 109 insertions(+), 17 deletions(-) create mode 100644 docs/stories/das_schweigende_spiegelbild.html create mode 100644 docs/stories/mit_gutem_gewissen.html create mode 100644 templates/story.html diff --git a/Cargo.toml b/Cargo.toml index 9bd7333..733ace4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,3 +11,4 @@ serde = {version = "1.0", features = ["derive"]} serde_json = "1.0" anyhow = "1.0" chrono = {version = "0.4", features = ["serde"]} +lopdf = "0.29" diff --git a/docs/index.html b/docs/index.html index 3574a1a..c2416a6 100644 --- a/docs/index.html +++ b/docs/index.html @@ -5,7 +5,7 @@ Home - Vithuran Vishnuthas - + diff --git a/docs/stories.html b/docs/stories.html index c0b2c2a..82b938d 100644 --- a/docs/stories.html +++ b/docs/stories.html @@ -5,7 +5,7 @@ Stories - Vithuran Vishnuthas - + @@ -37,7 +37,7 @@ Despite my linguistic difficulties to express myself, my love for story telling
- +

Das schweigende Spiegelbild

Das Spiegelbild verzweifelt in seiner Hilflosigkeit gegenüber seinem Ich.

@@ -49,7 +49,7 @@ Despite my linguistic difficulties to express myself, my love for story telling
- +

Mit gutem Gewissen

Der gefährliche Zauber von Leon wird von seinem wegweisenden Freund durchschaut. Kann er ihn stoppen?

diff --git a/docs/stories/das_schweigende_spiegelbild.html b/docs/stories/das_schweigende_spiegelbild.html new file mode 100644 index 0000000..acffb3f --- /dev/null +++ b/docs/stories/das_schweigende_spiegelbild.html @@ -0,0 +1,34 @@ + + + + + Das schweigende Spiegelbild - Vithuran Vishnuthas + + + + + + + +
+

Writer V2

+ Vithuran Vishnuthas +
+ +
+ +

Das schweigende Spiegelbild

+ Download PDF + +
+
+ Vithuran Vishnuthas © 2022 +
+ + + + + diff --git a/docs/stories/mit_gutem_gewissen.html b/docs/stories/mit_gutem_gewissen.html new file mode 100644 index 0000000..312f755 --- /dev/null +++ b/docs/stories/mit_gutem_gewissen.html @@ -0,0 +1,34 @@ + + + + + Mit gutem Gewissen - Vithuran Vishnuthas + + + + + + + +
+

Writer V2

+ Vithuran Vishnuthas +
+ +
+ +

Mit gutem Gewissen

+ Download PDF + +
+
+ Vithuran Vishnuthas © 2022 +
+ + + + + diff --git a/src/works/stories.rs b/src/works/stories.rs index c68745a..ccc01e0 100644 --- a/src/works/stories.rs +++ b/src/works/stories.rs @@ -5,26 +5,43 @@ use serde::{Deserialize, Serialize}; // derive from JSON // process to context for HTML #[derive(Debug, Deserialize, Serialize)] -pub struct Stories(pub Vec); +pub struct Stories(Vec); #[derive(Debug, Deserialize, Serialize)] -pub struct Story { - pub title: String, - pub description: String, - pub path_to_document: String, - pub number_of_pages: u16, - pub language: Language, - pub last_update: NaiveDate, +struct Story { + title: String, + description: String, + path_to_document: String, + number_of_pages: u16, + language: Language, + last_update: NaiveDate, } // see src/works/mod.rs for information of Works trait impl super::Works for Stories { + // render single pages for every story with the extracted text and a download button fn render_single_pages( &self, tera_instance: &tera::Tera, template_name: &str, ) -> anyhow::Result<()> { - !unimplemented!() + // TODO: Extract story pdf text + let mut result = Vec::new(); + for story in self.0.iter() { + 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(), + tera_instance.render(format!("{}.html", template_name).as_str(), &context)?, + )); + } + Ok(()) } } diff --git a/stories.json b/stories.json index 5b88987..b40342a 100644 --- a/stories.json +++ b/stories.json @@ -2,7 +2,7 @@ { "title": "Mit gutem Gewissen", "description": "Der gefährliche Zauber von Leon wird von seinem wegweisenden Freund durchschaut. Kann er ihn stoppen?", - "path_to_document": "./stories/mit_gutem_gewissen.pdf", + "path_to_document": "mit_gutem_gewissen.pdf", "number_of_pages": 7, "language": "German", "last_update": "2023-01-28" @@ -10,7 +10,7 @@ { "title": "Das schweigende Spiegelbild", "description": "Das Spiegelbild verzweifelt in seiner Hilflosigkeit gegenüber seinem Ich.", - "path_to_document": "./stories/das_schweigende_spiegelbild.pdf", + "path_to_document": "das_schweigende_spiegelbild.pdf", "number_of_pages": 2, "language": "German", "last_update": "2023-01-28" diff --git a/templates/base.html b/templates/base.html index 43117c3..ea8e04f 100644 --- a/templates/base.html +++ b/templates/base.html @@ -5,7 +5,7 @@ {% block title %}{% endblock title %} - Vithuran Vishnuthas - + diff --git a/templates/stories.html b/templates/stories.html index 07ebb40..a9efdb3 100644 --- a/templates/stories.html +++ b/templates/stories.html @@ -18,7 +18,7 @@ Despite my linguistic difficulties to express myself, my love for story telling