diff --git a/src/app/mod.rs b/src/app/mod.rs index d355a4d..97c9ef3 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -1,5 +1,6 @@ mod components; pub mod models; +mod pages; use leptos::*; use leptos_meta::*; @@ -14,18 +15,10 @@ pub fn App() -> impl IntoView { - }/> + + } /> + "Not Found" }/> } } - -#[component] -fn Home() -> impl IntoView { - view! { -
- - -
- } -} \ No newline at end of file diff --git a/src/app/models/post.rs b/src/app/models/post.rs index fa4d7d5..e2f982b 100644 --- a/src/app/models/post.rs +++ b/src/app/models/post.rs @@ -17,14 +17,13 @@ pub struct Post { cfg_if::cfg_if! { if #[cfg(feature = "ssr")] { - impl From for Post { - fn from(content: String) -> Self { + impl Post { + fn from_content(content: String) -> Option { use gray_matter::{Matter, engine::YAML}; let matter = Matter::::new(); let post_data = matter - .parse_with_struct::(&content) - .expect("Unable to parse md frontmatter"); + .parse_with_struct::(&content)?; let metadata = post_data.data; let content = post_data.content; @@ -34,14 +33,25 @@ cfg_if::cfg_if! { let mut html_output = String::new(); html::push_html(&mut html_output, parser); - Self { + Some(Self { metadata, content: html_output, - } + }) + } + + fn from_path(path: &std::path::Path) -> Option { + let content = std::fs::read_to_string(path); + let content = match content { + Ok(content) => content, + Err(e) => { + eprintln!("{:?}", e); + return None; + } + }; + + Self::from_content(content) } - } - impl Post { pub fn get_all(folder: &str) -> Result, String> { use std::{path::Path, fs::read_dir}; @@ -59,16 +69,9 @@ cfg_if::cfg_if! { } }; - let content = std::fs::read_to_string(path); - let content = match content { - Ok(content) => content, - Err(e) => { - eprintln!("{:?}", e); - continue; - } - }; - let post = Self::from(content); - posts.push(post); + if let Some(post) = Self::from_path(&path) { + posts.push(post); + } } Ok(posts) diff --git a/src/app/pages/home.rs b/src/app/pages/home.rs new file mode 100644 index 0000000..c9ab820 --- /dev/null +++ b/src/app/pages/home.rs @@ -0,0 +1,11 @@ +use leptos::*; +use super::super::components::{TopComponent, MonParcours}; +#[component] +pub fn Home() -> impl IntoView { + view! { +
+ + +
+ } +} \ No newline at end of file diff --git a/src/app/pages/mod.rs b/src/app/pages/mod.rs new file mode 100644 index 0000000..859cc08 --- /dev/null +++ b/src/app/pages/mod.rs @@ -0,0 +1,5 @@ +mod home; +pub use home::Home; + +mod posts; +pub use posts::PostList; \ No newline at end of file diff --git a/src/app/pages/posts.rs b/src/app/pages/posts.rs new file mode 100644 index 0000000..d216535 --- /dev/null +++ b/src/app/pages/posts.rs @@ -0,0 +1,13 @@ +use leptos::*; +use leptos_router::*; + +#[component] +pub fn PostList( + folder: String +) -> impl IntoView { + view! { +
+ Page List +
+ } +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 2dfa351..8ca9f24 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,11 +11,6 @@ cfg_if! { #[actix_web::main] async fn main() -> std::io::Result<()> { - let posts = app::models::Post::get_all("posts"); - for post in posts.unwrap() { - println!("{:?}", post); - } - // Setting this to None means we'll be using cargo-leptos and its env vars. let conf = get_configuration(None).await.unwrap();