diff --git a/src/utils/metadata.rs b/src/utils/metadata.rs index 40318fc..0bf3606 100644 --- a/src/utils/metadata.rs +++ b/src/utils/metadata.rs @@ -118,68 +118,46 @@ fn deserialize_metadata(text: &str) -> /// Fetch metadata from AST pub fn get<'a>(root: &'a AstNode<'a>, mtype: MType) -> MFile { root.children() - .map(|node| { - let generic = MFile { - hardbreaks: true, - ..MFile::default() - }; - - match &node.data.borrow().value { - // Extract metadata from frontmatter - NodeValue::FrontMatter(text) => match mtype { - MType::Blog => { - let metadata: FileMetadataBlog = deserialize_metadata(text); - MFile { - blog: Some(metadata.clone()), - hardbreaks: metadata.hardbreaks.unwrap_or_default(), - ..MFile::default() - } - } - MType::Contact => { - let mut metadata: FileMetadataContact = deserialize_metadata(text); - // Trim descriptions - if let Some(desc) = &mut metadata.description { - desc.clone_from(&desc.trim().into()); - } - MFile { - contact: Some(metadata), - ..MFile::default() - } - } - MType::Generic => generic, - MType::Index => MFile { - index: Some(deserialize_metadata(text)), + .map(|node| match &node.data.borrow().value { + // Extract metadata from frontmatter + NodeValue::FrontMatter(text) => match mtype { + MType::Blog => { + let metadata = deserialize_metadata::(text); + MFile { + blog: Some(metadata.clone()), + hardbreaks: metadata.hardbreaks.unwrap_or_default(), ..MFile::default() - }, - MType::Portfolio => MFile { - portfolio: Some(deserialize_metadata(text)), + } + } + MType::Contact => { + let mut metadata = deserialize_metadata::(text); + // Trim descriptions + if let Some(desc) = &mut metadata.description { + desc.clone_from(&desc.trim().into()); + } + MFile { + contact: Some(metadata), ..MFile::default() - }, - }, - _ => generic, - } - }) - .next() - .map_or_else( - || match mtype { - MType::Blog => MFile { - blog: Some(FileMetadataBlog::default()), + } + } + MType::Generic => MFile { + hardbreaks: deserialize_metadata(text), ..MFile::default() }, - MType::Contact => MFile { - contact: Some(FileMetadataContact::default()), - ..MFile::default() - }, - MType::Generic => MFile::default(), MType::Index => MFile { - index: Some(FileMetadataIndex::default()), + index: Some(deserialize_metadata(text)), ..MFile::default() }, MType::Portfolio => MFile { - portfolio: Some(FileMetadataPortfolio::default()), + portfolio: Some(deserialize_metadata(text)), ..MFile::default() }, }, - |data| data, - ) + _ => MFile { + hardbreaks: true, + ..MFile::default() + }, + }) + .next() + .unwrap() }