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 --- src/works/stories.rs | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'src') 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(()) } } -- cgit v1.2.3