Skip to content

Commit

Permalink
use method
Browse files Browse the repository at this point in the history
  • Loading branch information
CrackTheCode016 committed Aug 26, 2023
1 parent 9c46c9a commit 4a2bd12
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 16 deletions.
2 changes: 1 addition & 1 deletion posts/metadata.json
Original file line number Diff line number Diff line change
@@ -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"}]
[{"title":"Wasm blog!??!?","id":"wasm","date":"Aug 23rd 2023","author":"badery","peek":"A short, real post on WASM!","md_name":"./posts/wasm.md"}]
1 change: 0 additions & 1 deletion scripts/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/components/blog_list.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
8 changes: 1 addition & 7 deletions src/components/blog_post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Post> = 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")
Expand Down
5 changes: 0 additions & 5 deletions src/services/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,11 @@ pub struct Post {

impl Post {
pub fn get_post_from_metadata(metadata: String, id: String) -> Result<Post> {
// console::log_1(&metadata.clone().into());
let metadata: Vec<Post> = serde_json::from_str(&metadata)?;
let post = metadata
.iter()
.find(|p| p.id == id)
.expect("post not found");
Ok(post.clone())
}
/// JSON string to Post
pub fn from_str(str: String) -> Result<Post> {
serde_json::from_str(&str)
}
}

0 comments on commit 4a2bd12

Please sign in to comment.