format with rustfmt
This commit is contained in:
parent
c401da7c05
commit
8cb24ec0b3
|
@ -19,8 +19,8 @@ use once_cell::sync::Lazy;
|
||||||
use regex::{Captures, Regex};
|
use regex::{Captures, Regex};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
use gray_matter::Matter;
|
|
||||||
use gray_matter::engine::YAML;
|
use gray_matter::engine::YAML;
|
||||||
|
use gray_matter::Matter;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
fn extract_frontmatter(content: &str) -> Option<&str> {
|
fn extract_frontmatter(content: &str) -> Option<&str> {
|
||||||
|
@ -75,29 +75,40 @@ impl HtmlHandlebars {
|
||||||
let matter = Matter::<YAML>::new();
|
let matter = Matter::<YAML>::new();
|
||||||
let parsed = matter.parse(&ch.content);
|
let parsed = matter.parse(&ch.content);
|
||||||
let (content, new_content) = if let Some(data) = parsed.data {
|
let (content, new_content) = if let Some(data) = parsed.data {
|
||||||
|
|
||||||
debug!("Parsed frontmatter: {:?}", &data);
|
debug!("Parsed frontmatter: {:?}", &data);
|
||||||
let yaml_str = extract_frontmatter(&ch.content).unwrap_or_default();
|
let yaml_str = extract_frontmatter(&ch.content).unwrap_or_default();
|
||||||
let front_matter_result: Result<FrontMatter, serde_yaml::Error> = serde_yaml::from_str(yaml_str);
|
let front_matter_result: Result<FrontMatter, serde_yaml::Error> =
|
||||||
|
serde_yaml::from_str(yaml_str);
|
||||||
// let front_matter_result: Result<FrontMatter, serde_yaml::Error> = serde_yaml::from_str(&ch.content);
|
// let front_matter_result: Result<FrontMatter, serde_yaml::Error> = serde_yaml::from_str(&ch.content);
|
||||||
match front_matter_result {
|
match front_matter_result {
|
||||||
Ok(front_matter) => {
|
Ok(front_matter) => {
|
||||||
ctx.data.insert("is_frontmatter".to_owned(), json!("true"));
|
ctx.data.insert("is_frontmatter".to_owned(), json!("true"));
|
||||||
ctx.data.insert("og_title".to_owned(), json!(front_matter.title));
|
ctx.data
|
||||||
ctx.data.insert("og_description".to_owned(), json!(front_matter.description));
|
.insert("og_title".to_owned(), json!(front_matter.title));
|
||||||
ctx.data.insert("og_image_url".to_owned(), json!(front_matter.featured_image_url));
|
ctx.data
|
||||||
},
|
.insert("og_description".to_owned(), json!(front_matter.description));
|
||||||
|
ctx.data.insert(
|
||||||
|
"og_image_url".to_owned(),
|
||||||
|
json!(front_matter.featured_image_url),
|
||||||
|
);
|
||||||
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("Frontmatter: Deserialization error: {:?}", e);
|
eprintln!("Frontmatter: Deserialization error: {:?}", e);
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare new content without frontmatter for rendering
|
// Prepare new content without frontmatter for rendering
|
||||||
let new_content = parsed.content.trim_start();
|
let new_content = parsed.content.trim_start();
|
||||||
(utils::render_markdown(&new_content, ctx.html_config.curly_quotes), Some(new_content))
|
(
|
||||||
|
utils::render_markdown(&new_content, ctx.html_config.curly_quotes),
|
||||||
|
Some(new_content),
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
// No frontmatter, use original content
|
// No frontmatter, use original content
|
||||||
(utils::render_markdown(&ch.content, ctx.html_config.curly_quotes), None)
|
(
|
||||||
|
utils::render_markdown(&ch.content, ctx.html_config.curly_quotes),
|
||||||
|
None,
|
||||||
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
let fixed_content =
|
let fixed_content =
|
||||||
|
@ -179,8 +190,6 @@ impl HtmlHandlebars {
|
||||||
utils::fs::write_file(&ctx.destination, "index.html", rendered_index.as_bytes())?;
|
utils::fs::write_file(&ctx.destination, "index.html", rendered_index.as_bytes())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue