This commit is contained in:
Ondrej Vlach 2023-11-27 09:30:21 +01:00
parent 6efbfc0e9c
commit 74d0caa569
4 changed files with 42 additions and 10 deletions

View File

@ -1,3 +1,7 @@
[debug]
static_route = "http://localhost:8001"
cv_backend_path = "http://localhost:8002"
[default]
static_route = "http://localhost:8001"
cv_backend_path = "http://localhost:8002"

View File

@ -2,7 +2,7 @@
use rocket::{*, fairing::AdHoc};
use rocket_dyn_templates::Template;
use ::serde::Deserialize;
use tools::tera::{static_filter, translate_filter, calculate_age, insert_space_every, lang_entity, gravatar_link};
use tools::tera::{static_filter, translate_filter, calculate_age, insert_space_every, lang_entity, gravatar_link, format_date};
pub mod routes;
pub mod services;
@ -36,6 +36,7 @@ pub fn rocket_builder() -> Rocket<Build> {
engines.tera.register_filter("gravatar_link", gravatar_link);
// filters specific to API
engines.tera.register_filter("lang_entity", lang_entity);
engines.tera.register_filter("format_date", format_date);
Ok(())
})
).attach(

View File

@ -1,6 +1,6 @@
use std::{collections::HashMap, str::FromStr};
use chrono::{Utc, Datelike};
use chrono::{Utc, Datelike, NaiveDate};
use log::error;
use rocket_dyn_templates::tera::{Value, Error};
use ovlach_data::cv::chrono::from_string;
@ -56,7 +56,7 @@ pub fn lang_entity(
value: &Value,
_: &HashMap<String, rocket_dyn_templates::tera::Value>
) -> Result<Value, Error> {
error!("{:?}", value); // TODO: rewrite me!!!
// TODO: rewrite me!
return Ok(rocket_dyn_templates::tera::Value::String(format!("{}", value["en"].as_str().unwrap()))); // TODO: fix-me here!
}
@ -68,6 +68,30 @@ pub fn gravatar_link(
return Ok(rocket_dyn_templates::tera::Value::String(format!("https://gravatar.com/avatar/{}", val))); // TODO: fix-me here!
}
pub fn format_date(
value: &Value,
_: &HashMap<String, rocket_dyn_templates::tera::Value>
) -> Result<Value, Error> {
if value.is_null() {
return Ok(rocket_dyn_templates::tera::Value::String("".to_string()))
}
let val = value.as_str().unwrap();
if val == "" {
return Ok(rocket_dyn_templates::tera::Value::String("".to_string()))
}
let value = from_string(value.as_str().unwrap().into());
match value {
Ok(date) => Ok(rocket_dyn_templates::tera::Value::String(date.format("%Y").to_string())),
Err(e) => {
error!("Can't parse date: {}", e);
return Ok(rocket_dyn_templates::tera::Value::String("".to_string())) // TOdo: error
}
}
}
pub fn insert_space_every(
value: &Value,
args: &HashMap<String, rocket_dyn_templates::tera::Value>
@ -90,7 +114,6 @@ pub fn calculate_age(
value: &Value,
_: &HashMap<String, rocket_dyn_templates::tera::Value>
) -> Result<Value, Error> {
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 {

View File

@ -63,7 +63,7 @@
<div class="row">
<div class="col-md-6">
<h2 class="h2 fw-light mb-4">{{ "about-me" | translate(lang=lang) }} </h2>
<p>{{ cv.person.about | lang_entity }}</p>
<p>{{ cv.person.about | lang_entity(lang=lang) }}</p>
</div>
<div class="col-md-5 offset-lg-1">
<div class="row mt-2">
@ -147,8 +147,12 @@
<div class="h5">{{ job.title }} <span class="text-muted h6">at {{ job.company }}</span></div>
</div>
<div class="timeline-body px-4 pb-4">
<div class="text-muted text-small mb-3">May, 2015 - Present</div>
<div>{{ job.description | lang_entity }} </div>
{% if job.from | format_date(type="job") != job.from | format_date(type="job") %}
<div class="text-muted text-small mb-3">{{ job.from | format_date(type="job") }} - {{ job.to | format_date(type="job") }}</div>
{% else %}
<div class="text-muted text-small mb-3">{{ job.from | format_date(type="job") }}</div>
{% endif %}
<div>{{ job.description | lang_entity(lang=lang) }} </div>
</div>
</div>
{% endfor %}
@ -163,7 +167,7 @@
<div class="timeline-card timeline-card-success" data-aos="fade-in" data-aos-delay="0">
<div class="timeline-head px-4 pt-3">
{% if education.degree %}
<div class="h5">{{ education.degree | lang_entity }} <span class="text-muted h6">{{ education.school }}</span> </div>
<div class="h5">{{ education.degree | lang_entity(lang=lang) }} <span class="text-muted h6">{{ education.school }}</span> </div>
{% else %}
<div class="h5">{{ education.school }}</div>
{% endif %}
@ -171,8 +175,8 @@
<div class="timeline-body px-4 pb-4">
{% if education.description %}
<div class="text-muted text-small mb-3">2011 - 2013</div>
<div>{{ education.description | lang_entity }}</div>
<div class="text-muted text-small mb-3">{{ education.from | format_date(type="job") }} - {{ education.to | format_date(type="job") }}</div>
<div>{{ education.description | lang_entity(lang=lang) }}</div>
{% else %}
2011 - 2013
{% endif %}