Update leptos_icons + Add chrono datetime for matter + Add reading time estimation
This commit is contained in:
parent
4ab4b95d8a
commit
8b7e528bc9
12 changed files with 362 additions and 68 deletions
|
@ -1,6 +1,4 @@
|
|||
use leptos::*;
|
||||
use leptos_icons::FiIcon::FiExternalLink;
|
||||
use leptos_icons::*;
|
||||
|
||||
#[component]
|
||||
pub fn Link(
|
||||
|
@ -11,7 +9,7 @@ pub fn Link(
|
|||
view! {
|
||||
<a class="link" href={url} target="_blank">
|
||||
{ children() }
|
||||
<i><Icon icon=Icon::from(FiExternalLink) /></i>
|
||||
<i><leptos_icons::Icon icon=icondata::FiExternalLink /></i>
|
||||
</a>
|
||||
}
|
||||
}
|
|
@ -1,7 +1,5 @@
|
|||
use leptos::*;
|
||||
use leptos_router::*;
|
||||
use leptos_icons::FiIcon::FiMenu;
|
||||
use leptos_icons::*;
|
||||
|
||||
#[component]
|
||||
pub fn Nav() -> impl IntoView {
|
||||
|
@ -11,7 +9,7 @@ pub fn Nav() -> impl IntoView {
|
|||
<nav>
|
||||
<A href="/" class="nav-home">Florian RICHER</A>
|
||||
|
||||
<span class="nav-mobile" on:click=move |_| set_mobile_menu(!mobile_menu())><Icon icon=Icon::from(FiMenu)/></span>
|
||||
<span class="nav-mobile" on:click=move |_| set_mobile_menu(!mobile_menu())><leptos_icons::Icon icon=icondata::FiMenu/></span>
|
||||
<div class="nav-links" class:open=move || mobile_menu()>
|
||||
<A href="/experience" class="nav-link">Mon parcours</A>
|
||||
<A href="/posts" class="nav-link">Blog</A>
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use leptos::*;
|
||||
use leptos_icons::*;
|
||||
|
||||
#[component]
|
||||
pub fn SocialLinkContainer(
|
||||
|
@ -17,11 +16,11 @@ pub fn SocialLink(
|
|||
children: Children,
|
||||
#[prop(optional)]
|
||||
url: Option<String>,
|
||||
icon: Icon,
|
||||
icon: icondata::Icon,
|
||||
) -> impl IntoView {
|
||||
view! {
|
||||
<a class="social_link" href=url target="_blank">
|
||||
<Icon icon=icon />
|
||||
<leptos_icons::Icon icon=icon />
|
||||
<span>{ children() }</span>
|
||||
</a>
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use leptos::*;
|
||||
use leptos_icons::FaIcon::FaCaretDownSolid;
|
||||
use leptos_icons::*;
|
||||
|
||||
#[component]
|
||||
|
@ -113,7 +112,7 @@ impl IntoView for TimelineCard {
|
|||
<details>
|
||||
<summary>
|
||||
{ self.titles.collect_view() }
|
||||
<i><Icon icon=Icon::from(FaCaretDownSolid) /></i>
|
||||
<i><Icon icon=icondata::FaCaretDownSolid /></i>
|
||||
</summary>
|
||||
<div>{ self.cards.collect_view() }</div>
|
||||
</details>
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
use leptos::*;
|
||||
use leptos_icons::FaIcon::{FaGithubBrands, FaLinkedinBrands, FaEnvelopeSolid};
|
||||
use leptos_icons::*;
|
||||
|
||||
use super::*;
|
||||
|
||||
|
@ -28,9 +26,9 @@ pub fn TopComponent() -> impl IntoView {
|
|||
<a href="/posts".to_string()>Mon blog</a>
|
||||
</div>
|
||||
<SocialLinkContainer>
|
||||
<SocialLink icon=Icon::from(FaGithubBrands) url="https://github.com/mrdev023".to_string()>Github</SocialLink>
|
||||
<SocialLink icon=Icon::from(FaLinkedinBrands) url="https://www.linkedin.com/in/florian-richer-80960b129/".to_string()>Linkedin</SocialLink>
|
||||
<SocialLink icon=Icon::from(FaEnvelopeSolid) url="mailto:florian.richer@protonmail.com".to_string()>Mail</SocialLink>
|
||||
<SocialLink icon=icondata::FaGithubBrands url="https://github.com/mrdev023".to_string()>Github</SocialLink>
|
||||
<SocialLink icon=icondata::FaLinkedinBrands url="https://www.linkedin.com/in/florian-richer-80960b129/".to_string()>Linkedin</SocialLink>
|
||||
<SocialLink icon=icondata::FaEnvelopeSolid url="mailto:florian.richer@protonmail.com".to_string()>Mail</SocialLink>
|
||||
</SocialLinkContainer>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -5,10 +5,12 @@ pub struct PostMetadata {
|
|||
pub slug: String,
|
||||
pub image_path: String,
|
||||
pub title: String,
|
||||
pub date: String,
|
||||
pub date: chrono::DateTime<chrono::Local>,
|
||||
pub description: String,
|
||||
pub project_link: String,
|
||||
pub draft: bool,
|
||||
#[serde(default)]
|
||||
pub reading_time: u64,
|
||||
pub tags: Vec<String>,
|
||||
}
|
||||
|
||||
|
@ -34,12 +36,14 @@ cfg_if::cfg_if! {
|
|||
fn try_from(content: String) -> Result<Self, Self::Error> {
|
||||
use gray_matter::{Matter, engine::YAML};
|
||||
let matter = Matter::<YAML>::new();
|
||||
let post_data = matter
|
||||
let mut post_data = matter
|
||||
.parse_with_struct::<PostMetadata>(&content)
|
||||
.ok_or_else(|| PostDeserializationError::InvalidFrontMatter)?;
|
||||
|
||||
let content = post_data.content;
|
||||
|
||||
post_data.data.reading_time = crate::app::utils::reading_time::calculate_reading_time(&content);
|
||||
|
||||
use pulldown_cmark::{Parser, Options, html};
|
||||
let parser = Parser::new_ext(&content, Options::all());
|
||||
let mut html_output = String::new();
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use leptos::*;
|
||||
use leptos_icons::*;
|
||||
use leptos_router::*;
|
||||
use crate::app::{
|
||||
models::Post,
|
||||
|
@ -75,7 +74,7 @@ pub fn PostListCard(
|
|||
if post.metadata.draft {
|
||||
Some(view!{
|
||||
<div class="warning">
|
||||
<Icon icon=Icon::from(IoIcon::IoConstruct)/>
|
||||
<leptos_icons::Icon icon=icondata::IoConstruct/>
|
||||
</div>
|
||||
})
|
||||
} else {
|
||||
|
@ -87,7 +86,8 @@ pub fn PostListCard(
|
|||
<PostTags tags=post.metadata.tags.clone()/>
|
||||
<h2><A href=format!("/posts/{}", post.metadata.slug.clone())>{post.metadata.title.clone()}</A></h2>
|
||||
<p>{post.metadata.description.clone()}</p>
|
||||
<span>{post.metadata.date.clone()}</span>
|
||||
<span>{post.metadata.date.format("%d-%m-%Y").to_string()}</span>
|
||||
<span>{post.metadata.reading_time}</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
@ -146,7 +146,8 @@ pub fn PostElement() -> impl IntoView {
|
|||
<img src={post.metadata.image_path.clone()} alt=format!("Image {}", post.metadata.title)/>
|
||||
<h1>{post.metadata.title.clone()}</h1>
|
||||
<p>{post.metadata.description.clone()}</p>
|
||||
<span>{post.metadata.date.clone()}</span>
|
||||
<span>{post.metadata.date.format("%d-%m-%Y").to_string()}</span>
|
||||
<span>{post.metadata.reading_time}</span>
|
||||
<PostTags tags=post.metadata.tags.clone()/>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
pub(crate) mod data_src;
|
||||
pub(crate) mod data_src;
|
||||
pub(crate) mod reading_time;
|
10
src/app/utils/reading_time.rs
Normal file
10
src/app/utils/reading_time.rs
Normal file
|
@ -0,0 +1,10 @@
|
|||
pub fn calculate_reading_time(content: &String) -> u64 {
|
||||
let doc_read_time = estimated_read_time::Options::new()
|
||||
.word_length(5)
|
||||
.technical_document(true)
|
||||
.technical_difficulty(2)
|
||||
.build()
|
||||
.unwrap_or_default();
|
||||
|
||||
estimated_read_time::text(&content, &doc_read_time).seconds()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue