Skip to content

Commit d4de632

Browse files
committed
Bring back the RSS feed
Closes #307
1 parent e6989da commit d4de632

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

src/main.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ impl Blog {
9191
..ComrakOptions::default()
9292
};
9393

94-
let contents =
95-
comrak::markdown_to_html(&contents[end_of_yaml + 5..], &options);
94+
let contents = comrak::markdown_to_html(&contents[end_of_yaml + 5..], &options);
9695

9796
// finally, the url.
9897
let mut url = PathBuf::from(&*filename);
@@ -117,9 +116,7 @@ impl Blog {
117116

118117
// finally, sort the posts. oldest first.
119118

120-
posts.sort_by_key(|post|
121-
format!("{}-{}-{}", post.year, post.month, post.day)
122-
);
119+
posts.sort_by_key(|post| format!("{}-{}-{}", post.year, post.month, post.day));
123120

124121
posts.reverse();
125122

@@ -134,6 +131,8 @@ impl Blog {
134131

135132
self.render_posts()?;
136133

134+
self.render_feed()?;
135+
137136
self.compile_sass("app");
138137
self.compile_sass("fonts");
139138

@@ -205,6 +204,14 @@ impl Blog {
205204
Ok(())
206205
}
207206

207+
fn render_feed(&self) -> Result<(), Box<Error>> {
208+
let posts: Vec<_> = self.posts.iter().by_ref().take(10).collect();
209+
let data = json!({ "posts": posts });
210+
211+
self.render_template("feed.xml", "feed", data)?;
212+
Ok(())
213+
}
214+
208215
fn copy_static_files(&self) -> Result<(), Box<Error>> {
209216
use fs_extra::dir::{self, CopyOptions};
210217

templates/feed.hbs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
3+
<generator uri="https://blog.rust-lang.org/" version="0.1.0">Rust Blog</generator>
4+
<link href="https://blog.rust-lang.org/feed.xml" rel="self" type="application/atom+xml" />
5+
<link href="https://blog.rust-lang.org/" rel="alternate" type="text/html" />
6+
<title>Rust Blog</title>
7+
<subtitle>Empowering everyone to build reliable and efficient software.</subtitle>
8+
9+
{{#each posts}}
10+
<entry>
11+
<title>{{title}}</title>
12+
<link rel="alternate" href="https://blog.rust-lang.org/{{url}}" type="text/html" title="{{title}}" />
13+
<published>{{year}}-{{month}}-{{day}}</published>
14+
<id>https://blog.rust-lang.org/{{url}}</id>
15+
<content type="html" xml:base="https://blog.rust-lang.org/{{url}}">{{contents}}</content>
16+
</entry>
17+
{{/each}}
18+
</feed>

templates/headers.hbs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,6 @@
3737
<link rel="mask-icon" href="/images/safari-pinned-tab.svg" color="#5bbad5">
3838
<meta name="msapplication-TileColor" content="#00aba9">
3939
<meta name="theme-color" content="#ffffff">
40+
41+
<!-- atom -->
42+
<link type="application/atom+xml" rel="alternate" href="https://blog.rust-lang.org/feed.xml" title="Rust Blog" />

0 commit comments

Comments
 (0)