htoml

HTML page templates described with a toml config
Log | Files | Refs | README

commit 792e46bda065c0ca343a89b8b18d940b14e185b8
parent efea623811b03605fc3087d68fb7c9b8a9c311b8
Author: Jackson G. Kaindume <seestem@merely.tech>
Date:   Thu, 18 Aug 2022 18:52:33 +0200

Add about section

Diffstat:
Asrc/sections/about.rs | 79+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/sections/mod.rs | 9+++++++++
2 files changed, 88 insertions(+), 0 deletions(-)

diff --git a/src/sections/about.rs b/src/sections/about.rs @@ -0,0 +1,79 @@ +use crate::common::Export; +use crate::sections::{Section, SectionMetadata}; +use serde::Deserialize; +use std::path::PathBuf; + +#[derive(Deserialize, Clone)] +pub struct About { + /// Variant of about to use + pub variant: String, + /// Heading of about section + pub heading: String, + /// Paragraph text + pub paragraph: String, +} + +impl Section for About { + fn export(&self, metadata: &SectionMetadata) -> Export { + let mut html = "".to_string(); + let mut css = "".to_string(); + + match self.variant.as_str() { + "basic" => { + css = format!( + r#".htoml_about{{ + margin-top: 0; + padding: 2em; + height: 200px; + color: {}; + }}"#, + metadata.tertiary_color + ); + + html = format!( + r#" + <section class='htoml_about'> + <h3>{}<h3> + <p>{}</p> + </section>"#, + self.heading, self.paragraph + ); + } + "frosh" => { + css = format!( + r#".htoml_about{{ + margin-top: 0; + padding: 2em; + height: 200px; + color: {}; + }} + + .htoml_about p{{ + font-size: 1.7em; + }} + "#, + metadata.secondary_color + ); + html = format!( + r#" + <section class='htoml_about'> + <h3>{}</h3> + <p>{}</p> + </section>"#, + self.heading, self.paragraph + ); + } + _ => panic!("Invalid About variant"), + } + Export { html, css } + } +} + +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + let result = 2 + 2; + assert_eq!(result, 4); + } +} diff --git a/src/sections/mod.rs b/src/sections/mod.rs @@ -1,6 +1,7 @@ use crate::common::Export; use serde::Deserialize; +pub mod about; pub mod hero; pub mod navbar; @@ -27,6 +28,8 @@ pub struct Sections { pub navbar: Option<navbar::Navbar>, /// Hero section pub hero: Option<hero::Hero>, + /// About Section + pub about: Option<about::About>, } impl Sections { @@ -47,6 +50,12 @@ impl Sections { css = format!("{}{}", css, hero_export.css); } + if let Some(about) = &self.about { + let about_export = about.export(metadata); + html = format!("{}{}", html, about_export.html); + css = format!("{}{}", css, about_export.css); + } + Export { html, css } } }