get rid of unwrap/expect and do things right
This commit is contained in:
parent
109a1c1e84
commit
bd54b95f1b
1 changed files with 13 additions and 13 deletions
|
@ -2,9 +2,8 @@ use crate::components::article::ArticleData;
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
// Can this merge with ArticleData somehow?
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct TomlData {
|
struct ArticleFrontmatter {
|
||||||
content_type: String,
|
content_type: String,
|
||||||
title: String,
|
title: String,
|
||||||
date: String,
|
date: String,
|
||||||
|
@ -27,19 +26,20 @@ pub async fn slingshot(path: String) -> Result<Vec<ArticleData>, ServerFnError>
|
||||||
.expect("Problem processing markdown");
|
.expect("Problem processing markdown");
|
||||||
let content = html_from_md.content;
|
let content = html_from_md.content;
|
||||||
let _toc = html_from_md.toc;
|
let _toc = html_from_md.toc;
|
||||||
let frontmatter = html_from_md
|
|
||||||
.frontmatter
|
|
||||||
.expect(&format!("error getting frontmatter for {}", &file).to_string());
|
|
||||||
|
|
||||||
let toml: TomlData =
|
if let Some(front_raw) = html_from_md.frontmatter {
|
||||||
toml::from_str(&frontmatter.code_block.unwrap().source).unwrap();
|
if let Some(front_code) = front_raw.code_block {
|
||||||
|
let toml: ArticleFrontmatter =
|
||||||
|
toml::from_str(&front_code.source)?;
|
||||||
|
|
||||||
articles.push(ArticleData {
|
articles.push(ArticleData {
|
||||||
content_type: toml.content_type,
|
content_type: toml.content_type,
|
||||||
title: toml.title,
|
title: toml.title,
|
||||||
date: toml.date,
|
date: toml.date,
|
||||||
content,
|
content,
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue