summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWriterV2 <primary-v2@protonmail.com>2026-05-05 17:12:34 +0200
committerWriterV2 <primary-v2@protonmail.com>2026-05-05 17:12:34 +0200
commitf6a02d2f3c96db0274915d0d1be28a711e9a3821 (patch)
tree632075acf9ef09146c9d2c33d595fca50d15e931 /src
parent6f9b52954da265066edfca19464d1ef56e29cb53 (diff)
Update story data
Diffstat (limited to 'src')
-rw-r--r--src/main.rs49
-rw-r--r--src/page.rs6
2 files changed, 53 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index 1108c23..d7df3f6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,7 @@
use anyhow::{Context, Result};
use maud::{html, Markup};
use serde::Deserialize;
+use toml::value::Date;
use self::page::Page;
@@ -23,21 +24,65 @@ impl page::Page for Vec<Story> {
}
)
}
+
+ fn prepare_content(&self) -> Result<()> {
+ for story in self {
+ std::fs::copy(&story.path, story.format_local_pdf_path())?;
+ }
+ Ok(())
+ }
+}
+
+#[derive(Deserialize, Debug)]
+enum StoryLanguage {
+ German,
+ English,
+}
+
+impl std::fmt::Display for StoryLanguage {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "{:?}", self)
+ }
}
#[derive(Deserialize)]
struct Story {
name: String,
description: String,
+ language: StoryLanguage,
+ upload_date: Date,
+ update_date: Option<Date>,
+ path: String,
}
impl Story {
fn render_as_card(self) -> Markup {
html!(card {
- span { (self.name) }
- span { (self.description) }
+ h2 {
+ span { (self.name) }
+ }
+ p { (self.description) } br
+ span { "Language: " (self.language) }
+ span { "Uploaded on: " (self.upload_date) }
+ @if let Some(update_date) = self.update_date {
+ span { "Updated on: " (update_date) }
+ }
+ br {}
+ a href=(&self.format_pdf_path()) download
+ {
+ "PDF"
+ }
})
}
+
+ fn format_pdf_path(&self) -> String {
+ let snake_case_name = self.name.to_lowercase().replace(" ", "_");
+ format!("stories/{}.pdf", snake_case_name)
+ }
+
+ fn format_local_pdf_path(&self) -> String {
+ format!("dist/{}", self.format_pdf_path())
+ }
}
fn main() -> Result<()> {
diff --git a/src/page.rs b/src/page.rs
index 747f243..a849a14 100644
--- a/src/page.rs
+++ b/src/page.rs
@@ -111,6 +111,7 @@ pub trait Page: Sized {
}
fn write_page(self) -> Result<()> {
+ self.prepare_content()?;
let page_html = self.render_page().into_string();
let mut cfg = Cfg::new();
cfg.minify_css = true;
@@ -121,4 +122,9 @@ pub trait Page: Sized {
.with_context(|| format!("Failed to write {}", html_path))?;
Ok(())
}
+
+ // use this to validate and prepare the content for the page, e.g. files
+ fn prepare_content(&self) -> Result<()> {
+ Ok(())
+ }
}