Skip to content

Commit 1c2f12c

Browse files
authored
Merge pull request #294 from rodneylab/fix__replace_serde_yaml
fix: 💫 replace serde_yaml with yaml-rust2
2 parents b4cac28 + aada175 commit 1c2f12c

File tree

3 files changed

+87
-23
lines changed

3 files changed

+87
-23
lines changed

Cargo.lock

Lines changed: 69 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ pulldown-cmark-escape = "0.10.0"
3737
reqwest = { version = "0.12.2", features = ["json"] }
3838
serde = { version = "1.0.196", features = ["derive"] }
3939
serde_json = "1.0.113"
40-
serde_yaml = "0.9.33"
4140
textwrap = "0.16.0"
4241
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
4342
url = "2.5.0"
43+
yaml-rust2 = "0.8"
4444

4545
[dev-dependencies]
4646
assert_cmd = "2.0.13"

src/lib.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use std::{
3131
path::Path,
3232
pin::Pin,
3333
};
34+
use yaml_rust2::YamlLoader;
3435

3536
pub struct ParseInputOptions {
3637
canonical_root_url: Option<String>,
@@ -369,8 +370,22 @@ pub async fn update_html<P1: AsRef<Path>, P2: AsRef<Path>>(
369370

370371
let (frontmatter_yaml, markdown) = strip_frontmatter(&markdown);
371372
let frontmatter = match frontmatter_yaml {
372-
Some(value) => match serde_yaml::from_str(value) {
373-
Ok(frontmatter_value) => frontmatter_value,
373+
Some(value) => match YamlLoader::load_from_str(value) {
374+
Ok(frontmatter_value) => {
375+
let doc = &frontmatter_value[0];
376+
let title = doc["title"].as_str().map(std::string::ToString::to_string);
377+
let description = doc["description"]
378+
.as_str()
379+
.map(std::string::ToString::to_string);
380+
let canonical_url = doc["canonical_url"]
381+
.as_str()
382+
.map(std::string::ToString::to_string);
383+
Frontmatter {
384+
title,
385+
description,
386+
canonical_url,
387+
}
388+
}
374389
Err(_) => Frontmatter {
375390
title: None,
376391
description: None,

0 commit comments

Comments
 (0)