Update gray_matter to 0.2

This commit is contained in:
Zoey 2021-08-19 13:00:31 -07:00
parent c3eabe3a83
commit e06c4371f4
3 changed files with 13 additions and 8 deletions

4
Cargo.lock generated
View file

@ -442,9 +442,9 @@ dependencies = [
[[package]]
name = "gray_matter"
version = "0.1.0"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "deed89f803cf559d60ec5cf204f35a9a803dbdf39182b431791b3f0a36a2b9f2"
checksum = "bbe4e5d3deddf3e8ed33124c1846a57aadf1c0b80b237738311852fab96e48ea"
dependencies = [
"json",
"regex",

View file

@ -8,7 +8,7 @@ anyhow = "1"
extract-frontmatter = "2.1"
fs_extra = "1.2"
futures = { version = "0.3", optional = true }
gray_matter = "0.1"
gray_matter = "0.2"
handlebars = "4.1"
hotwatch = { version = "0.4", optional = true }
lol_html = "0.3"

View file

@ -37,7 +37,7 @@ pub struct SiteConfig {
}
/// Struct for the front matter in templates. (nothing here yet)
#[derive(Debug, Deserialize)]
#[derive(Debug, Default, Deserialize)]
pub struct TemplateMetadata {}
/// Struct containing data to be sent to templates when rendering them.
@ -48,7 +48,7 @@ struct TemplateData<'a> {
}
/// Struct for the front matter in pages.
#[derive(Debug, Deserialize)]
#[derive(Debug, Default, Deserialize)]
pub struct PageMetadata {
/// The page's title.
pub title: Option<String>,
@ -230,18 +230,23 @@ impl<'a> SiteBuilder<'a> {
let input = std::fs::read_to_string(page_path)
.with_context(|| format!("Failed to read page at {}", page_path.display()))?;
let page = self.matter.matter_struct::<PageMetadata>(input);
let page = self.matter.parse(&input);
let page_metadata = if let Some(data) = page.data {
data.deserialize()?
} else {
PageMetadata::default()
};
let parser = Parser::new_ext(&page.content, Options::all());
let mut page_html = String::new();
pulldown_cmark::html::push_html(&mut page_html, parser);
let out = self.reg.render(
&page.data.template.unwrap_or_else(|| "base".to_string()),
&page_metadata.template.unwrap_or_else(|| "base".to_string()),
&TemplateData { page: &page_html },
)?;
let title = match &page.data.title {
let title = match &page_metadata.title {
Some(page_title) => format!("{} / {}", self.site.config.title, page_title),
_ => self.site.config.title.clone(),
};