mirror of
https://github.com/zyllian/webdog.git
synced 2025-05-09 18:16:40 -07:00
add ability for the built-in frontmatter parser to also output
This commit is contained in:
parent
624853f3ba
commit
8b7620b0bd
1 changed files with 25 additions and 1 deletions
|
@ -1,4 +1,4 @@
|
||||||
use serde::de::DeserializeOwned;
|
use serde::{de::DeserializeOwned, Serialize};
|
||||||
|
|
||||||
/// Very basic YAML front matter parser.
|
/// Very basic YAML front matter parser.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -30,3 +30,27 @@ where
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T> FrontMatter<T>
|
||||||
|
where
|
||||||
|
T: Serialize,
|
||||||
|
{
|
||||||
|
/// Formats the front matter and content to a string ready for saving.
|
||||||
|
pub fn format(&self) -> eyre::Result<String> {
|
||||||
|
let mut output = String::new();
|
||||||
|
|
||||||
|
if let Some(data) = &self.data {
|
||||||
|
output.push_str("---\n");
|
||||||
|
output.push_str(&serde_yml::to_string(data)?);
|
||||||
|
output.push_str("---\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
output.push_str(&self.content);
|
||||||
|
|
||||||
|
if !output.ends_with('\n') {
|
||||||
|
output.push('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(output)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue