was i stupid?
This commit is contained in:
parent
4ae660983f
commit
fe0d15509c
1 changed files with 31 additions and 53 deletions
|
@ -118,68 +118,46 @@ fn deserialize_metadata<T: Default + serde::de::DeserializeOwned>(text: &str) ->
|
||||||
/// Fetch metadata from AST
|
/// Fetch metadata from AST
|
||||||
pub fn get<'a>(root: &'a AstNode<'a>, mtype: MType) -> MFile {
|
pub fn get<'a>(root: &'a AstNode<'a>, mtype: MType) -> MFile {
|
||||||
root.children()
|
root.children()
|
||||||
.map(|node| {
|
.map(|node| match &node.data.borrow().value {
|
||||||
let generic = MFile {
|
// Extract metadata from frontmatter
|
||||||
hardbreaks: true,
|
NodeValue::FrontMatter(text) => match mtype {
|
||||||
..MFile::default()
|
MType::Blog => {
|
||||||
};
|
let metadata = deserialize_metadata::<FileMetadataBlog>(text);
|
||||||
|
MFile {
|
||||||
match &node.data.borrow().value {
|
blog: Some(metadata.clone()),
|
||||||
// Extract metadata from frontmatter
|
hardbreaks: metadata.hardbreaks.unwrap_or_default(),
|
||||||
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)),
|
|
||||||
..MFile::default()
|
..MFile::default()
|
||||||
},
|
}
|
||||||
MType::Portfolio => MFile {
|
}
|
||||||
portfolio: Some(deserialize_metadata(text)),
|
MType::Contact => {
|
||||||
|
let mut metadata = deserialize_metadata::<FileMetadataContact>(text);
|
||||||
|
// Trim descriptions
|
||||||
|
if let Some(desc) = &mut metadata.description {
|
||||||
|
desc.clone_from(&desc.trim().into());
|
||||||
|
}
|
||||||
|
MFile {
|
||||||
|
contact: Some(metadata),
|
||||||
..MFile::default()
|
..MFile::default()
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
_ => generic,
|
MType::Generic => MFile {
|
||||||
}
|
hardbreaks: deserialize_metadata(text),
|
||||||
})
|
|
||||||
.next()
|
|
||||||
.map_or_else(
|
|
||||||
|| match mtype {
|
|
||||||
MType::Blog => MFile {
|
|
||||||
blog: Some(FileMetadataBlog::default()),
|
|
||||||
..MFile::default()
|
..MFile::default()
|
||||||
},
|
},
|
||||||
MType::Contact => MFile {
|
|
||||||
contact: Some(FileMetadataContact::default()),
|
|
||||||
..MFile::default()
|
|
||||||
},
|
|
||||||
MType::Generic => MFile::default(),
|
|
||||||
MType::Index => MFile {
|
MType::Index => MFile {
|
||||||
index: Some(FileMetadataIndex::default()),
|
index: Some(deserialize_metadata(text)),
|
||||||
..MFile::default()
|
..MFile::default()
|
||||||
},
|
},
|
||||||
MType::Portfolio => MFile {
|
MType::Portfolio => MFile {
|
||||||
portfolio: Some(FileMetadataPortfolio::default()),
|
portfolio: Some(deserialize_metadata(text)),
|
||||||
..MFile::default()
|
..MFile::default()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|data| data,
|
_ => MFile {
|
||||||
)
|
hardbreaks: true,
|
||||||
|
..MFile::default()
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.next()
|
||||||
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue