diff --git a/posts/metadata.json b/posts/metadata.json index 2e38190..126b30e 100644 --- a/posts/metadata.json +++ b/posts/metadata.json @@ -1 +1 @@ -[{"title":"Wasm blog!??!?","id":"wasm","date":"Aug 23rd 2023","author":"badery","peek":"A short, real post on WASM!","md_name":"./posts/wasm.md"},{"title":"real","id":"real","date":"Aug 23rd 2023","author":"badery","peek":"A short, real post on WASM!","md_name":"./posts/real.md"}] \ No newline at end of file +[{"title":"Wasm blog!??!?","id":"wasm","date":"Aug 23rd 2023","author":"badery","peek":"A short, real post on WASM!","md_name":"./posts/wasm.md"}] \ No newline at end of file diff --git a/scripts/src/main.rs b/scripts/src/main.rs index b8dba6c..719f06a 100644 --- a/scripts/src/main.rs +++ b/scripts/src/main.rs @@ -2,7 +2,6 @@ use std::fs::File; use std::io::Error; use std::io::{Read, Write}; -use serde::{Deserialize, Serialize}; use serde_json::Result as SerdeResult; use wasm_blog::services::types::Post; use std::path::PathBuf; diff --git a/src/components/blog_list.rs b/src/components/blog_list.rs index f646bd1..65cfdc1 100644 --- a/src/components/blog_list.rs +++ b/src/components/blog_list.rs @@ -1,5 +1,3 @@ -use serde::{Deserialize, Serialize}; -use serde_json::Result; use yew::prelude::*; use yew::virtual_dom::VNode; use yew_router::prelude::{use_navigator, Navigator}; diff --git a/src/components/blog_post.rs b/src/components/blog_post.rs index 0ea3777..7aa785c 100644 --- a/src/components/blog_post.rs +++ b/src/components/blog_post.rs @@ -23,13 +23,7 @@ pub fn post(props: &BlogPostProps) -> HtmlResult { let metadata = use_file("/posts/metadata.json".to_string())?; let md: String = use_file(path.clone())?; if metadata != "not found" { - let metadata: Vec = serde_json::from_str(&metadata).expect("Invalid metadata"); - let post: &Post = metadata - .iter() - .find(|p| p.id == props.id) - .expect("post not found"); - let post = post.clone(); - console::log_1(&post.title.clone().into()); + let post = Post::get_post_from_metadata(metadata, props.id.clone()).expect("could not parse post"); let html = html::Html::from_html_unchecked( markdown::to_html_with_options(&md, &Options::gfm()) .expect("Unable to parse markdown") diff --git a/src/services/types.rs b/src/services/types.rs index 99edd7a..94af49f 100644 --- a/src/services/types.rs +++ b/src/services/types.rs @@ -14,7 +14,6 @@ pub struct Post { impl Post { pub fn get_post_from_metadata(metadata: String, id: String) -> Result { - // console::log_1(&metadata.clone().into()); let metadata: Vec = serde_json::from_str(&metadata)?; let post = metadata .iter() @@ -22,8 +21,4 @@ impl Post { .expect("post not found"); Ok(post.clone()) } - /// JSON string to Post - pub fn from_str(str: String) -> Result { - serde_json::from_str(&str) - } } \ No newline at end of file