mirror of
https://github.com/zyllian/zyllian.github.io.git
synced 2025-05-10 02:26:45 -07:00
Update gray_matter to 0.2
This commit is contained in:
parent
bd18c6015b
commit
e4579c45f0
3 changed files with 13 additions and 8 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -442,9 +442,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gray_matter"
|
name = "gray_matter"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "deed89f803cf559d60ec5cf204f35a9a803dbdf39182b431791b3f0a36a2b9f2"
|
checksum = "bbe4e5d3deddf3e8ed33124c1846a57aadf1c0b80b237738311852fab96e48ea"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"json",
|
"json",
|
||||||
"regex",
|
"regex",
|
||||||
|
|
|
@ -8,7 +8,7 @@ anyhow = "1"
|
||||||
extract-frontmatter = "2.1"
|
extract-frontmatter = "2.1"
|
||||||
fs_extra = "1.2"
|
fs_extra = "1.2"
|
||||||
futures = { version = "0.3", optional = true }
|
futures = { version = "0.3", optional = true }
|
||||||
gray_matter = "0.1"
|
gray_matter = "0.2"
|
||||||
handlebars = "4.1"
|
handlebars = "4.1"
|
||||||
hotwatch = { version = "0.4", optional = true }
|
hotwatch = { version = "0.4", optional = true }
|
||||||
lol_html = "0.3"
|
lol_html = "0.3"
|
||||||
|
|
15
src/lib.rs
15
src/lib.rs
|
@ -37,7 +37,7 @@ pub struct SiteConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Struct for the front matter in templates. (nothing here yet)
|
/// Struct for the front matter in templates. (nothing here yet)
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Default, Deserialize)]
|
||||||
pub struct TemplateMetadata {}
|
pub struct TemplateMetadata {}
|
||||||
|
|
||||||
/// Struct containing data to be sent to templates when rendering them.
|
/// 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.
|
/// Struct for the front matter in pages.
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Default, Deserialize)]
|
||||||
pub struct PageMetadata {
|
pub struct PageMetadata {
|
||||||
/// The page's title.
|
/// The page's title.
|
||||||
pub title: Option<String>,
|
pub title: Option<String>,
|
||||||
|
@ -230,18 +230,23 @@ impl<'a> SiteBuilder<'a> {
|
||||||
|
|
||||||
let input = std::fs::read_to_string(page_path)
|
let input = std::fs::read_to_string(page_path)
|
||||||
.with_context(|| format!("Failed to read page at {}", page_path.display()))?;
|
.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 parser = Parser::new_ext(&page.content, Options::all());
|
||||||
let mut page_html = String::new();
|
let mut page_html = String::new();
|
||||||
pulldown_cmark::html::push_html(&mut page_html, parser);
|
pulldown_cmark::html::push_html(&mut page_html, parser);
|
||||||
|
|
||||||
let out = self.reg.render(
|
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 },
|
&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),
|
Some(page_title) => format!("{} / {}", self.site.config.title, page_title),
|
||||||
_ => self.site.config.title.clone(),
|
_ => self.site.config.title.clone(),
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue