diff options
| -rw-r--r-- | Cargo.lock | 128 | ||||
| -rw-r--r-- | Cargo.toml | 1 | ||||
| -rw-r--r-- | src/main.rs | 49 | ||||
| -rw-r--r-- | src/page.rs | 6 |
4 files changed, 53 insertions, 131 deletions
@@ -48,15 +48,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" [[package]] -name = "android_system_properties" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" -dependencies = [ - "libc", -] - -[[package]] name = "anyhow" version = "1.0.100" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -152,35 +143,12 @@ dependencies = [ ] [[package]] -name = "cc" -version = "1.2.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97463e1064cb1b1c1384ad0a0b9c8abd0988e2a91f52606c80ef14aadb63e36" -dependencies = [ - "find-msvc-tools", - "shlex", -] - -[[package]] name = "cfg-if" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[package]] -name = "chrono" -version = "0.4.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2" -dependencies = [ - "iana-time-zone", - "js-sys", - "num-traits", - "wasm-bindgen", - "windows-link", -] - -[[package]] name = "cobs" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -233,12 +201,6 @@ dependencies = [ ] [[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - -[[package]] name = "cow-utils" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -390,12 +352,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" [[package]] -name = "find-msvc-tools" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a3076410a55c90011c298b04d0cfa770b00fa04e1e3c97d3f6c9de105a03844" - -[[package]] name = "flate2" version = "1.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -459,30 +415,6 @@ dependencies = [ ] [[package]] -name = "iana-time-zone" -version = "0.1.64" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33e57f83510bb73707521ebaffa789ec8caf86f9657cad665b092b581d40e9fb" -dependencies = [ - "android_system_properties", - "core-foundation-sys", - "iana-time-zone-haiku", - "js-sys", - "log", - "wasm-bindgen", - "windows-core", -] - -[[package]] -name = "iana-time-zone-haiku" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" -dependencies = [ - "cc", -] - -[[package]] name = "indexmap" version = "2.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1240,7 +1172,6 @@ name = "portfolio-website" version = "0.1.0" dependencies = [ "anyhow", - "chrono", "maud", "minify-html", "serde", @@ -1513,12 +1444,6 @@ dependencies = [ ] [[package]] -name = "shlex" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" - -[[package]] name = "simd-abstraction" version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1795,65 +1720,12 @@ dependencies = [ ] [[package]] -name = "windows-core" -version = "0.62.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" -dependencies = [ - "windows-implement", - "windows-interface", - "windows-link", - "windows-result", - "windows-strings", -] - -[[package]] -name = "windows-implement" -version = "0.60.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.110", -] - -[[package]] -name = "windows-interface" -version = "0.59.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.110", -] - -[[package]] name = "windows-link" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" [[package]] -name = "windows-result" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" -dependencies = [ - "windows-link", -] - -[[package]] -name = "windows-strings" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" -dependencies = [ - "windows-link", -] - -[[package]] name = "winnow" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -9,6 +9,5 @@ edition = "2021" serde = {version = "1.0", features = ["derive"]} anyhow = "1.0" maud = { version = "0.27.0" } -chrono = "0.4.38" toml = "1.0.7" minify-html = "0.18.1" 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(()) + } } |
