Skip to content

Commit f964392

Browse files
committed
Replace serde_yaml with toml
1 parent e755357 commit f964392

File tree

5 files changed

+70
-37
lines changed

5 files changed

+70
-37
lines changed

Cargo.lock

Lines changed: 51 additions & 18 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
@@ -11,13 +11,13 @@ lazy_static = "=1.5.0"
1111
serde = "=1.0.218"
1212
serde_derive = "=1.0.218"
1313
serde_json = "=1.0.140"
14-
serde_yaml = "=0.9.34-deprecated"
1514
comrak = { version = "=0.36.0", features = ["bon"] }
1615
rayon = "=1.10.0"
1716
regex = "=1.11.1"
1817
sass-rs = "=0.2.2"
1918
chrono = "=0.4.40"
2019
tera = "=1.20.0"
20+
toml = "=0.8.20"
2121

2222
[workspace]
2323
members = ["serve"]

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ something big, please open an issue before working on it, so we can make sure
4646
that it's something that will eventually be accepted.
4747

4848
When writing a new blog post, keep in mind the file headers:
49-
```
50-
---
51-
layout: post
52-
title: Title of the blog post
53-
author: Blog post author (or on behalf of which team)
54-
release: true (to be only used for official posts about Rust releases announcements)
55-
---
49+
```md
50+
+++
51+
layout = "post"
52+
title = "Title of the blog post"
53+
author = "Blog post author (or on behalf of which team)"
54+
release = true # (to be only used for official posts about Rust releases announcements)
55+
+++
5656
```
5757

5858
### Snapshot testing

src/blogs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::posts::Post;
22
use serde_derive::{Deserialize, Serialize};
33
use std::path::{Path, PathBuf};
44

5-
static MANIFEST_FILE: &str = "blog.yml";
5+
static MANIFEST_FILE: &str = "blog.toml";
66
static POSTS_EXT: &str = "md";
77

88
#[derive(Deserialize)]
@@ -47,7 +47,7 @@ pub struct Blog {
4747
impl Blog {
4848
fn load(prefix: PathBuf, dir: &Path) -> eyre::Result<Self> {
4949
let manifest_content = std::fs::read_to_string(dir.join(MANIFEST_FILE))?;
50-
let manifest: Manifest = serde_yaml::from_str(&manifest_content)?;
50+
let manifest: Manifest = toml::from_str(&manifest_content)?;
5151

5252
let mut posts = Vec::new();
5353
for entry in std::fs::read_dir(dir)? {

src/posts.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use serde_derive::{Deserialize, Serialize};
55
use std::path::{Path, PathBuf};
66

77
#[derive(Debug, PartialEq, Deserialize)]
8-
struct YamlHeader {
8+
struct TomlHeader {
99
title: String,
1010
author: String,
1111
#[serde(default)]
@@ -55,18 +55,18 @@ impl Post {
5555
));
5656
}
5757

58-
// yaml headers.... we know the first four bytes of each file are "---\n"
58+
// toml headers.... we know the first four bytes of each file are "+++\n"
5959
// so we need to find the end. we need the fours to adjust for those first bytes
60-
let end_of_yaml = contents[4..].find("---").unwrap() + 4;
61-
let yaml = &contents[..end_of_yaml];
62-
let YamlHeader {
60+
let end_of_toml = contents[4..].find("+++").unwrap() + 4;
61+
let toml = &contents[4..end_of_toml];
62+
let TomlHeader {
6363
author,
6464
title,
6565
release,
6666
team: team_string,
6767
layout,
68-
} = serde_yaml::from_str(yaml)?;
69-
// next, the contents. we add + to get rid of the final "---\n\n"
68+
} = toml::from_str(toml)?;
69+
7070
let options = comrak::Options {
7171
render: comrak::RenderOptions::builder().unsafe_(true).build(),
7272
extension: comrak::ExtensionOptions::builder()
@@ -78,8 +78,8 @@ impl Post {
7878
..comrak::Options::default()
7979
};
8080

81-
// Content starts after "---\n" (we don't assume an extra newline)
82-
let contents = comrak::markdown_to_html(&contents[end_of_yaml + 4..], &options);
81+
// Content starts after "+++\n" (we don't assume an extra newline)
82+
let contents = comrak::markdown_to_html(&contents[end_of_toml + 4..], &options);
8383

8484
// finally, the url.
8585
let mut url = PathBuf::from(&*filename);

0 commit comments

Comments
 (0)