format with rustfmt

This commit is contained in:
sspaeti 2024-02-20 18:24:43 +01:00
parent c401da7c05
commit 8cb24ec0b3
1 changed files with 24 additions and 15 deletions

View File

@ -19,8 +19,8 @@ use once_cell::sync::Lazy;
use regex::{Captures, Regex};
use serde_json::json;
use gray_matter::Matter;
use gray_matter::engine::YAML;
use gray_matter::Matter;
use serde::Deserialize;
fn extract_frontmatter(content: &str) -> Option<&str> {
@ -75,29 +75,40 @@ impl HtmlHandlebars {
let matter = Matter::<YAML>::new();
let parsed = matter.parse(&ch.content);
let (content, new_content) = if let Some(data) = parsed.data {
debug!("Parsed frontmatter: {:?}", &data);
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);
match front_matter_result {
Ok(front_matter) => {
ctx.data.insert("is_frontmatter".to_owned(), json!("true"));
ctx.data.insert("og_title".to_owned(), json!(front_matter.title));
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));
},
ctx.data.insert("is_frontmatter".to_owned(), json!("true"));
ctx.data
.insert("og_title".to_owned(), json!(front_matter.title));
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) => {
eprintln!("Frontmatter: Deserialization error: {:?}", e);
},
}
}
// Prepare new content without frontmatter for rendering
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 {
// 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 =
@ -179,8 +190,6 @@ impl HtmlHandlebars {
utils::fs::write_file(&ctx.destination, "index.html", rendered_index.as_bytes())?;
}
Ok(())
}