fix generic
This commit is contained in:
parent
8b5c128bfd
commit
8e1b036386
1 changed files with 37 additions and 35 deletions
|
@ -335,12 +335,17 @@ fn deserialize_metadata<T: Default + serde::de::DeserializeOwned>(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 {
|
||||
.map(|node| {
|
||||
let generic = FileMetadata {
|
||||
hardbreaks: true,
|
||||
..FileMetadata::default()
|
||||
};
|
||||
|
||||
match &node.data.borrow().value {
|
||||
// Extract metadata from frontmatter
|
||||
NodeValue::FrontMatter(text) => Some(match mtype {
|
||||
NodeValue::FrontMatter(text) => match mtype {
|
||||
TypeFileMetadata::Blog => {
|
||||
let metadata: FileMetadataBlog = deserialize_metadata(text);
|
||||
|
||||
FileMetadata {
|
||||
blog: Some(metadata.clone()),
|
||||
hardbreaks: metadata.hardbreaks.unwrap_or_default(),
|
||||
|
@ -349,21 +354,16 @@ pub fn get_metadata<'a>(root: &'a AstNode<'a>, mtype: &TypeFileMetadata) -> File
|
|||
}
|
||||
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 => FileMetadata {
|
||||
hardbreaks: true,
|
||||
..FileMetadata::default()
|
||||
},
|
||||
TypeFileMetadata::Generic => generic,
|
||||
TypeFileMetadata::Index => FileMetadata {
|
||||
index: Some(deserialize_metadata(text)),
|
||||
..FileMetadata::default()
|
||||
|
@ -372,9 +372,11 @@ pub fn get_metadata<'a>(root: &'a AstNode<'a>, mtype: &TypeFileMetadata) -> File
|
|||
portfolio: Some(deserialize_metadata(text)),
|
||||
..FileMetadata::default()
|
||||
},
|
||||
}),
|
||||
_ => None,
|
||||
},
|
||||
_ => generic,
|
||||
}
|
||||
})
|
||||
.next()
|
||||
.map_or_else(
|
||||
|| match mtype {
|
||||
TypeFileMetadata::Blog => FileMetadata {
|
||||
|
|
Loading…
Reference in a new issue