Skip to content

Commit 5e048eb

Browse files
committed
create the Inside Rust blog
Along the way: - blog post layouts are now mandatory, but must be "post" - blog manifest specifies if the `team` attribute is required - if so, it should have the format `team name <team-url>`
1 parent 2a670dc commit 5e048eb

11 files changed

+103
-56
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ edition = "2018"
66

77
[dependencies]
88
handlebars = "1.1.0"
9+
lazy_static = "1.4.0"
910
serde = "1.0"
1011
serde_derive = "1.0"
1112
serde_yaml = "0.8"
1213
serde_json = "1.0"
1314
comrak = "0.4"
1415
fs_extra = "1.1.0"
16+
regex = "1.3"
1517
sass-rs = "0.2.1"
1618
time = "0.1.41"

posts/2018-01-03-new-years-rust-a-call-for-community-blogposts.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: "New Year's Rust: A Call for Community Blogposts"
33
author: "The Rust Core Team"
4+
layout: post
45
---
56

67
'Tis the season for people and communities to reflect and set goals- and the Rust team is

posts/2018-10-30-help-test-rust-2018.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: "Help test Rust 2018"
33
author: "The Rust Core Team"
4+
layout: post
45
---
56

67
Back in July, we talked about ["Rust 2018"]. In short, we are launching a

posts/blog.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ title: Rust Blog
22
index-title: The Rust Programming Language Blog
33
description: Empowering everyone to build reliable and efficient software.
44
maintained-by: the Rust Team
5+
requires-team: false
6+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
layout: post
3+
title: "Announcing the Inside Rust blog!"
4+
author: Niko Matsakis
5+
description: "A new blog where the Rust team can post updates on the latest developments"
6+
team: the core team <https://www.rust-lang.org/governance/teams/core>
7+
---
8+
9+
Welcome to the inaugural post of the **Inside Rust** blog! This is a
10+
new blog where the various Rust teams and working groups can post
11+
updates about new developments. It's a great place to watch if you're
12+
interested in following along with Rust development -- and a
13+
particularly great place to watch if you're interested in contributing
14+
to Rust. Expect to see updates on new projects, calls for help, design
15+
notes, and other similar items. Thanks for reading!
16+

posts/inside-rust/blog.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
title: Inside Rust blog
2+
index-title: the Inside Rust blog
3+
description: Want to follow along with Rust development? Curious how you might get involved? Take a look!
4+
maintained-by: the Rust Teams
5+
requires-team: true

src/blogs.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ static POSTS_EXT: &str = "md";
88

99
#[derive(Deserialize)]
1010
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
11-
struct Manifest {
12-
title: String,
13-
index_title: String,
14-
description: String,
15-
maintained_by: String,
11+
pub(crate) struct Manifest {
12+
pub(crate) title: String,
13+
pub(crate) index_title: String,
14+
pub(crate) description: String,
15+
pub(crate) maintained_by: String,
16+
pub(crate) requires_team: bool,
1617
}
1718

1819
#[derive(Serialize)]
@@ -36,7 +37,7 @@ impl Blog {
3637
let path = entry?.path();
3738
let ext = path.extension().and_then(|e| e.to_str());
3839
if path.metadata()?.file_type().is_file() && ext == Some(POSTS_EXT) {
39-
posts.push(Post::open(&path)?);
40+
posts.push(Post::open(&path, &manifest)?);
4041
}
4142
}
4243

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl Generator {
159159
"post": post,
160160
});
161161

162-
self.render_template(path.join(filename), "post", data)?;
162+
self.render_template(path.join(filename), &post.layout, data)?;
163163
Ok(())
164164
}
165165

src/posts.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
use crate::blogs::Manifest;
12
use comrak::ComrakOptions;
3+
use regex::Regex;
24
use serde_derive::{Deserialize, Serialize};
35
use std::error::Error;
46
use std::path::{Path, PathBuf};
@@ -9,11 +11,14 @@ struct YamlHeader {
911
author: String,
1012
#[serde(default)]
1113
release: bool,
14+
team: Option<String>,
15+
layout: String,
1216
}
1317

1418
#[derive(Debug, Clone, Serialize)]
1519
pub(crate) struct Post {
1620
pub(crate) filename: String,
21+
pub(crate) layout: String,
1722
pub(crate) title: String,
1823
pub(crate) author: String,
1924
pub(crate) year: String,
@@ -24,10 +29,13 @@ pub(crate) struct Post {
2429
pub(crate) url: String,
2530
pub(crate) published: String,
2631
pub(crate) release: bool,
32+
pub(crate) has_team: bool,
33+
pub(crate) team: String,
34+
pub(crate) team_url: String,
2735
}
2836

2937
impl Post {
30-
pub(crate) fn open(path: &Path) -> Result<Self, Box<dyn Error>> {
38+
pub(crate) fn open(path: &Path, manifest: &Manifest) -> Result<Self, Box<dyn Error>> {
3139
// yeah this might blow up, but it won't
3240
let filename = path.file_name().unwrap().to_str().unwrap();
3341

@@ -49,6 +57,8 @@ impl Post {
4957
author,
5058
title,
5159
release,
60+
team: team_string,
61+
layout,
5262
} = serde_yaml::from_str(yaml)?;
5363
// next, the contents. we add + to get rid of the final "---\n\n"
5464
let options = ComrakOptions {
@@ -84,6 +94,34 @@ impl Post {
8494

8595
let published = published.rfc3339().to_string();
8696

97+
// validate for now that the layout is specified as "post"
98+
match &*layout {
99+
"post" => (),
100+
_ => panic!("blog post at path `{}` should have layout `post`", path.display()),
101+
};
102+
103+
// Enforce extra conditions
104+
if manifest.requires_team && team_string.is_none() {
105+
panic!("blog post at path `{}` lacks team/team_url metadata", path.display());
106+
}
107+
108+
// If they supplied team, it should look like `team-text <team-url>`
109+
let (team, team_url) = match team_string {
110+
Some(s) => {
111+
lazy_static::lazy_static! {
112+
static ref R: Regex = Regex::new(r"(?P<name>[^<]*) <(?P<url>[^>]+)>").unwrap();
113+
}
114+
let captures = match R.captures(&s) {
115+
Some(c) => c,
116+
None => panic!("team from path `{}` should have format `$name <$url>`",
117+
path.display()),
118+
};
119+
(Some(captures["name"].to_string()), Some(captures["url"].to_string()))
120+
}
121+
122+
None => (None, None)
123+
};
124+
87125
Ok(Self {
88126
filename,
89127
title,
@@ -96,6 +134,10 @@ impl Post {
96134
url,
97135
published,
98136
release,
137+
layout,
138+
has_team: team.is_some(),
139+
team: team.unwrap_or_default(),
140+
team_url: team_url.unwrap_or_default(),
99141
})
100142
}
101143
}

0 commit comments

Comments
 (0)