diff --git a/Cargo.toml b/Cargo.toml index 4d9e66b..0ca21da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,8 +19,8 @@ serde = "1.0" chrono = { version = "0.4", features = ["serde"] } # https://carlosted.github.io/icondata/ -leptos_icons = "0.2.0" -icondata = "0.3.0" +leptos_icons = "0.2" +icondata = "0.3" # dependecies for client (enable when csr or hydrate set) wasm-bindgen = { version = "0.2", optional = true } diff --git a/src/app/components/datetime.rs b/src/app/components/datetime.rs new file mode 100644 index 0000000..06ce4b3 --- /dev/null +++ b/src/app/components/datetime.rs @@ -0,0 +1,41 @@ +use leptos::*; +use chrono::Datelike; + +fn human_datetime(datetime: &chrono::DateTime) -> String { + format!( + "{day} {month} {year}", + day = datetime.day(), + month = human_month(datetime.month()), + year = datetime.year() + ) +} + +fn human_month<'a>(month: u32) -> &'a str { + match month { + 1 => "Jan.", + 2 => "Feb.", + 3 => "Mar.", + 4 => "Avr.", + 5 => "Mai", + 6 => "Juin", + 7 => "Juillet", + 8 => "Août", + 9 => "Sept.", + 10 => "Oct.", + 11 => "Nov.", + 12 => "Dec.", + _ => "Invalide" + } +} + +#[component] +pub fn DateTime( + datetime: chrono::DateTime +) -> impl IntoView { + view! { + + + { human_datetime(&datetime) } + + } +} \ No newline at end of file diff --git a/src/app/components/mod.rs b/src/app/components/mod.rs index 169c72b..3e3c192 100644 --- a/src/app/components/mod.rs +++ b/src/app/components/mod.rs @@ -32,3 +32,11 @@ mod nav; pub use nav::Nav; pub use mon_parcours::MonParcours; + +mod reading_time; + +pub use reading_time::ReadingTime; + +mod datetime; + +pub use datetime::DateTime; \ No newline at end of file diff --git a/src/app/components/reading_time.rs b/src/app/components/reading_time.rs new file mode 100644 index 0000000..b24be6d --- /dev/null +++ b/src/app/components/reading_time.rs @@ -0,0 +1,24 @@ +use leptos::*; + +fn human_reading_time(reading_time: u64) -> String { + match reading_time { + 0..=60 => format!("{reading_time}s"), + _ => { + let min = reading_time / 60; + let secs = reading_time - min * 60; + format!("{min}min {secs}s") + } + } +} + +#[component] +pub fn ReadingTime( + time: u64 +) -> impl IntoView { + view! { + + + { human_reading_time(time) } + + } +} \ No newline at end of file diff --git a/src/app/pages/posts.rs b/src/app/pages/posts.rs index 9dde85c..c5b94e1 100644 --- a/src/app/pages/posts.rs +++ b/src/app/pages/posts.rs @@ -3,11 +3,7 @@ use leptos_router::*; use crate::app::{ models::Post, components::{ - Loading, Nav - }, - utils::{ - datetime::human_datetime, - reading_time::human_reading_time + Loading, Nav, ReadingTime, DateTime } }; @@ -90,8 +86,8 @@ pub fn PostListCard(

{post.metadata.title.clone()}

{post.metadata.description.clone()}

- {human_datetime(&post.metadata.date)} - {human_reading_time(post.metadata.reading_time)} + + } @@ -150,8 +146,8 @@ pub fn PostElement() -> impl IntoView { format!("Image

{post.metadata.title.clone()}

{post.metadata.description.clone()}

- {human_datetime(&post.metadata.date)} - {human_reading_time(post.metadata.reading_time)} + + diff --git a/src/app/utils/mod.rs b/src/app/utils/mod.rs index c7f923a..e474011 100644 --- a/src/app/utils/mod.rs +++ b/src/app/utils/mod.rs @@ -1,5 +1,4 @@ #[cfg(feature = "ssr")] pub(crate) mod data_src; -pub(crate) mod datetime; pub(crate) mod reading_time; \ No newline at end of file diff --git a/src/app/utils/reading_time.rs b/src/app/utils/reading_time.rs index ac8fee3..143a06c 100644 --- a/src/app/utils/reading_time.rs +++ b/src/app/utils/reading_time.rs @@ -8,15 +8,4 @@ pub fn calculate_reading_time(content: &String) -> u64 { .unwrap_or_default(); estimated_read_time::text(&content, &doc_read_time).seconds() -} - -pub fn human_reading_time(reading_time: u64) -> String { - match reading_time { - 0..=60 => format!("{reading_time}s"), - _ => { - let min = reading_time / 60; - let secs = reading_time - min * 60; - format!("{min}min {secs}s") - } - } } \ No newline at end of file diff --git a/style/icon_container.css b/style/icon_container.css new file mode 100644 index 0000000..58fbc02 --- /dev/null +++ b/style/icon_container.css @@ -0,0 +1,9 @@ +@layer components { + .icon_container { + @apply flex items-center gap-2; + + & > svg { + @apply scale-125; + } + } +} \ No newline at end of file diff --git a/style/portfolio.css b/style/portfolio.css index 6ef2319..70dac52 100644 --- a/style/portfolio.css +++ b/style/portfolio.css @@ -11,6 +11,7 @@ @import './timeline.css'; @import './top_component.css'; @import './nav.css'; +@import './icon_container.css'; /*@import './mermaid.css';*/ body {