Skip to content

Commit aed3a79

Browse files
committed
create the Inside Rust blog
Along the way: - blog post layouts are now mandatory (and respected) - inside rust blog posts are tagged with a distinct layout (`post-inside-rust`) - this layout requires `team` and `team_url` metadata
1 parent e38d1c3 commit aed3a79

File tree

7 files changed

+82
-1
lines changed

7 files changed

+82
-1
lines changed

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
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
layout: post-inside-rust
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: core
7+
team_url: https://www.rust-lang.org/governance/teams/core
8+
---
9+
10+
Welcome to the inaugural post of the **Inside Rust** blog! This is a
11+
new blog where the various Rust teams and working groups can post
12+
updates about new developments. It's a great place to watch if you're
13+
interested in following along with Rust development -- and a
14+
particularly great place to watch if you're interested in contributing
15+
to Rust. Expect to see updates on new projects, calls for help, design
16+
notes, and other similar items. Thanks for reading!
17+

posts/inside-rust/blog.yml

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

src/main.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ mod posts;
33

44
use crate::blogs::Blog;
55
use crate::posts::Post;
6+
use crate::posts::PostLayout;
67
use handlebars::{Context, Handlebars, Helper, HelperResult, Output, RenderContext, RenderError};
78
use sass_rs::{compile_file, Options};
89
use serde_derive::Serialize;
@@ -159,7 +160,12 @@ impl Generator {
159160
"post": post,
160161
});
161162

162-
self.render_template(path.join(filename), "post", data)?;
163+
let template_name = match post.layout {
164+
PostLayout::Post => "post",
165+
PostLayout::PostInsideRust => "post-inside-rust",
166+
};
167+
168+
self.render_template(path.join(filename), template_name, data)?;
163169
Ok(())
164170
}
165171

src/posts.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ struct YamlHeader {
99
author: String,
1010
#[serde(default)]
1111
release: bool,
12+
team: Option<String>,
13+
team_url: Option<String>,
14+
layout: String,
1215
}
1316

1417
#[derive(Debug, Clone, Serialize)]
1518
pub(crate) struct Post {
1619
pub(crate) filename: String,
20+
pub(crate) layout: PostLayout,
1721
pub(crate) title: String,
1822
pub(crate) author: String,
1923
pub(crate) year: String,
@@ -24,6 +28,14 @@ pub(crate) struct Post {
2428
pub(crate) url: String,
2529
pub(crate) published: String,
2630
pub(crate) release: bool,
31+
pub(crate) team: String,
32+
pub(crate) team_url: String,
33+
}
34+
35+
#[derive(Debug, Copy, Clone, Serialize)]
36+
pub(crate) enum PostLayout {
37+
Post,
38+
PostInsideRust,
2739
}
2840

2941
impl Post {
@@ -49,6 +61,9 @@ impl Post {
4961
author,
5062
title,
5163
release,
64+
team,
65+
team_url,
66+
layout,
5267
} = serde_yaml::from_str(yaml)?;
5368
// next, the contents. we add + to get rid of the final "---\n\n"
5469
let options = ComrakOptions {
@@ -84,6 +99,23 @@ impl Post {
8499

85100
let published = published.rfc3339().to_string();
86101

102+
let layout = match &*layout {
103+
"post" => PostLayout::Post,
104+
"post-inside-rust" => PostLayout::PostInsideRust,
105+
_ => panic!("blog post at path `{}` has an unrecognized layout", path.display()),
106+
};
107+
108+
// Enforce extra conditions
109+
match layout {
110+
PostLayout::PostInsideRust => {
111+
if team.is_none() || team_url.is_none() {
112+
panic!("blog post at path `{}` lacks team/team_url metadata", path.display());
113+
}
114+
}
115+
116+
_ => { }
117+
}
118+
87119
Ok(Self {
88120
filename,
89121
title,
@@ -96,6 +128,9 @@ impl Post {
96128
url,
97129
published,
98130
release,
131+
layout,
132+
team: team.unwrap_or_default(),
133+
team_url: team_url.unwrap_or_default(),
99134
})
100135
}
101136
}

templates/post-inside-rust.hbs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{{#*inline "page"}}
2+
<section id="{{post.title}}" class="white">
3+
<div class="w-100 mw-none ph3 mw8-m mw8-l center f3">
4+
<header>
5+
<h2>{{ post.title }}</h2>
6+
<div class="highlight"></div>
7+
</header>
8+
9+
<div class="publish-date-author">{{month_name post.month}} {{post.day}}, {{post.year}} &middot; {{post.author}} &middot; <a href="{{post.team_url}}">{{post.team}}</a></div>
10+
11+
<div class="post">
12+
{{{ post.contents }}}
13+
</div>
14+
</div>
15+
</section>
16+
{{/inline}}
17+
{{~> (parent)~}}

0 commit comments

Comments
 (0)