diff --git a/Cargo.lock b/Cargo.lock index 96eab0d..e4b1d9b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -194,7 +194,9 @@ checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" dependencies = [ "android-tzdata", "iana-time-zone", + "js-sys", "num-traits", + "wasm-bindgen", "windows-targets", ] @@ -266,6 +268,30 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "crossbeam-deque" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" +dependencies = [ + "cfg-if", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "memoffset", + "scopeguard", +] + [[package]] name = "crossbeam-utils" version = "0.8.16" @@ -567,15 +593,15 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "globset" -version = "0.4.13" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "759c97c1e17c55525b57192c06a267cda0ac5210b222d6b82189a2338fa1c13d" +checksum = "57da3b9b5b85bd66f31093f8c408b90a74431672542466497dcbdfdc02034be1" dependencies = [ "aho-corasick", "bstr", - "fnv", "log", - "regex", + "regex-automata 0.4.3", + "regex-syntax 0.8.2", ] [[package]] @@ -735,17 +761,16 @@ dependencies = [ [[package]] name = "ignore" -version = "0.4.20" +version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbe7873dab538a9a44ad79ede1faf5f30d49f9a5c883ddbab48bce81b64b7492" +checksum = "747ad1b4ae841a78e8aba0d63adbfbeaea26b517b63705d47856b73015d27060" dependencies = [ + "crossbeam-deque", "globset", - "lazy_static", "log", "memchr", - "regex", + "regex-automata 0.4.3", "same-file", - "thread_local", "walkdir", "winapi-util", ] @@ -853,9 +878,9 @@ checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" [[package]] name = "libm" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7012b1bbb0719e1097c47611d3898568c546d597c2e74d66f6087edd5233ff4" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" [[package]] name = "linux-raw-sys" @@ -909,6 +934,15 @@ version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" +[[package]] +name = "memoffset" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" +dependencies = [ + "autocfg", +] + [[package]] name = "mime" version = "0.3.17" @@ -1099,8 +1133,9 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "ovlach_data" version = "0.1.0" -source = "git+https://glpat-Ju_qUN9Yh8qa5rEnd6T7:glpat-Ju_qUN9Yh8qa5rEnd6T7@gitlab.nanobyte.cz/ondrej/ov-site-api-data.git?tag=v0.0.1#85e59a8c7b2ddf768751a82cde1b70d99ad6147e" +source = "git+https://glpat-Ju_qUN9Yh8qa5rEnd6T7:glpat-Ju_qUN9Yh8qa5rEnd6T7@gitlab.nanobyte.cz/ondrej/ov-site-api-data.git?branch=add_missing_fields#16c3522851e763b883c1bdc2a235bad039f943d9" dependencies = [ + "chrono", "rocket", "serde", ] @@ -1109,6 +1144,7 @@ dependencies = [ name = "ovlach_frontend" version = "0.1.0" dependencies = [ + "chrono", "fern", "log", "ovlach_data", diff --git a/Cargo.toml b/Cargo.toml index 497ed1b..31a161f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,4 +14,5 @@ rocket = { version = "0.5.0", features = ["json"] } rocket_dyn_templates = { version = "0.1.0", features = ["tera"]} reqwest = { version = "0.11", features = ["json"] } tokio = { version = "1", features = ["full"] } -ovlach_data = { git = "https://glpat-Ju_qUN9Yh8qa5rEnd6T7:glpat-Ju_qUN9Yh8qa5rEnd6T7@gitlab.nanobyte.cz/ondrej/ov-site-api-data.git", tag = "v0.0.1"} \ No newline at end of file +ovlach_data = { git = "https://glpat-Ju_qUN9Yh8qa5rEnd6T7:glpat-Ju_qUN9Yh8qa5rEnd6T7@gitlab.nanobyte.cz/ondrej/ov-site-api-data.git", branch = "add_missing_fields"} +chrono = "0.4.31" \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 4c3f6a0..8a02666 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,7 @@ use std::collections::HashMap; use rocket::{*, fairing::AdHoc}; use rocket_dyn_templates::{Template, tera::Value}; use ::serde::Deserialize; -use tools::tera::{static_filter, translate_filter}; +use tools::tera::{static_filter, translate_filter, calculate_age, insert_space_every}; pub mod routes; pub mod services; @@ -32,6 +32,8 @@ pub fn rocket_builder() -> Rocket { Template::try_custom(|engines| { engines.tera.register_filter("static", static_filter); engines.tera.register_filter("translate", translate_filter); + engines.tera.register_filter("calculate_age", calculate_age); + engines.tera.register_filter("insert_space_every", insert_space_every); Ok(()) }) ).attach( diff --git a/src/routes/root.rs b/src/routes/root.rs index 0ff852b..2f6d5e0 100644 --- a/src/routes/root.rs +++ b/src/routes/root.rs @@ -9,7 +9,8 @@ use crate::{PresentationConfig, services::cv::fetch_cv_data_from_backend, CVBack #[derive(Serialize, Debug)] struct RootPage { static_host: String, - cv: CV + cv: CV, + download_cv_url: String, } #[get("/")] @@ -17,7 +18,8 @@ pub async fn index(presentation_config: &State, cv_config: & let context = match fetch_cv_data_from_backend(cv_config.cv_backend_path.clone()).await { Ok(cv) => RootPage { static_host: presentation_config.static_route.clone(), - cv + cv, + download_cv_url: "FIXME!".to_string(), }, Err(e) => { error!("Can't fetch CV data from backend {:?}", e); diff --git a/src/tools/tera.rs b/src/tools/tera.rs index 994a1c3..12ffceb 100644 --- a/src/tools/tera.rs +++ b/src/tools/tera.rs @@ -1,7 +1,11 @@ use std::collections::HashMap; +use chrono::{Utc, Datelike}; +use log::error; use rocket_dyn_templates::tera::{Value, Error}; +use ovlach_data::cv::chrono::from_string; +// TODO: tenhle modul je trochu prasacky.. pub fn static_filter( value: &Value, @@ -16,4 +20,48 @@ pub fn translate_filter( args: &HashMap ) -> Result { return Ok(rocket_dyn_templates::tera::Value::String(format!("{}", value.as_str().unwrap()))); // TODO: fix-me here! -} \ No newline at end of file +} + +pub fn insert_space_every( + value: &Value, + args: &HashMap +) -> Result { + let mut input = value.as_u64().unwrap().to_string(); + let times = args.get("times").unwrap().as_u64().unwrap(); + let mut result = String::new(); + + for (index, ch) in input.chars().enumerate() { + if index > 0 && index as u64 % times == 0 { + result.push(' '); + } + result.push(ch); + } + + Ok(rocket_dyn_templates::tera::Value::String(result)) +} + +pub fn calculate_age( + value: &Value, + args: &HashMap +) -> Result { + error!("{:?}", value.as_str()); + //let s = value.to_string().trim_matches('"'); // TODO: unwrap here! + let value = from_string(value.as_str().unwrap().into()); + match value { + Ok(value) => { + let current_date = Utc::now().naive_utc().date(); + let mut age = current_date.year() - value.year(); + + // Adjust age if the birthday hasn't occurred yet this year + age = if current_date.month() < value.month() || + (current_date.month() == value.month() && current_date.day() < value.day()) { + age - 1 + } else { + age + }; + + Ok(rocket_dyn_templates::tera::Value::String(age.to_string())) + } + Err(e) => panic!("Can't parse date: {}", e) + } +} diff --git a/templates/base.html.tera b/templates/base.html.tera index 167cfa7..1e748c0 100644 --- a/templates/base.html.tera +++ b/templates/base.html.tera @@ -28,7 +28,7 @@
-

Walter Patterson

+

{{ cv.person.name }} {{ cv.person.surname }}

@@ -40,9 +59,8 @@
-

About Me

-

Hello! I’m Walter Patterson. I am passionate about UI/UX design and Web Design. I am a skilled front-end developer and master of graphic design tools such as Photoshop and Sketch. I am a quick learner and a team worker that gets the job done.

-

I can easily capitalize on low hanging fruits and quickly maximize timely deliverables for real-time schemas.

+

{{ "About Me" | translate }}

+

LoremIPSUM chat gpt pomuze!

@@ -51,32 +69,28 @@
Age
-
28
+
{{ cv.person.birthday | calculate_age }}
Email
-
walter@company.com
-
-
-
Skype
-
-
-
username@skype.com
+
{{ cv.person.email }}
Phone
-
+0718-111-0011
-
-
-
Address
-
-
-
131 W, City Center, New York, U.S.A
+
+ {{cv.person.phone | insert_space_every(times=3) }}
+ {% if cv.person.address %} +
+
Address
+
+
+
{{ cv.person.address }}
+
+ {% endif %}