From 8e1b036386a1026e24c19d2f363e10bb607af87a Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 9 Nov 2024 15:43:29 +0100 Subject: [PATCH] fix generic --- src/misc/markdown.rs | 72 +++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/src/misc/markdown.rs b/src/misc/markdown.rs index dcf1e2f..50fab1b 100644 --- a/src/misc/markdown.rs +++ b/src/misc/markdown.rs @@ -335,46 +335,48 @@ fn deserialize_metadata(text: &str) -> /// Fetch metadata from AST pub fn get_metadata<'a>(root: &'a AstNode<'a>, mtype: &TypeFileMetadata) -> FileMetadata { root.children() - .find_map(|node| match &node.data.borrow().value { - // Extract metadata from frontmatter - NodeValue::FrontMatter(text) => Some(match mtype { - TypeFileMetadata::Blog => { - let metadata: FileMetadataBlog = deserialize_metadata(text); + .map(|node| { + let generic = FileMetadata { + hardbreaks: true, + ..FileMetadata::default() + }; - FileMetadata { - blog: Some(metadata.clone()), - hardbreaks: metadata.hardbreaks.unwrap_or_default(), + match &node.data.borrow().value { + // Extract metadata from frontmatter + NodeValue::FrontMatter(text) => match mtype { + TypeFileMetadata::Blog => { + let metadata: FileMetadataBlog = deserialize_metadata(text); + FileMetadata { + blog: Some(metadata.clone()), + hardbreaks: metadata.hardbreaks.unwrap_or_default(), + ..FileMetadata::default() + } + } + TypeFileMetadata::Contact => { + let mut metadata: FileMetadataContact = deserialize_metadata(text); + // Trim descriptions + if let Some(desc) = &mut metadata.description { + desc.clone_from(&desc.trim().into()); + } + FileMetadata { + contact: Some(metadata), + ..FileMetadata::default() + } + } + TypeFileMetadata::Generic => generic, + TypeFileMetadata::Index => FileMetadata { + index: Some(deserialize_metadata(text)), ..FileMetadata::default() - } - } - TypeFileMetadata::Contact => { - let mut metadata: FileMetadataContact = deserialize_metadata(text); - - // Trim descriptions - if let Some(desc) = &mut metadata.description { - desc.clone_from(&desc.trim().into()); - } - - FileMetadata { - contact: Some(metadata), + }, + TypeFileMetadata::Portfolio => FileMetadata { + portfolio: Some(deserialize_metadata(text)), ..FileMetadata::default() - } - } - TypeFileMetadata::Generic => FileMetadata { - hardbreaks: true, - ..FileMetadata::default() + }, }, - TypeFileMetadata::Index => FileMetadata { - index: Some(deserialize_metadata(text)), - ..FileMetadata::default() - }, - TypeFileMetadata::Portfolio => FileMetadata { - portfolio: Some(deserialize_metadata(text)), - ..FileMetadata::default() - }, - }), - _ => None, + _ => generic, + } }) + .next() .map_or_else( || match mtype { TypeFileMetadata::Blog => FileMetadata {