Skip to content

Commit 1f7dfb7

Browse files
authored
Merge pull request #327 from sondr3/feed
Bring back the RSS feed
2 parents 63f9304 + 11b98c1 commit 1f7dfb7

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
<author>
9+
<name>Maintained by the Rust Team.</name>
10+
<uri>https://github.com/rust-lang/blog.rust-lang.org/</uri>
11+
</author>
12+
13+
{{#each posts}}
14+
<entry>
15+
<title>{{title}}</title>
16+
<link rel="alternate" href="https://blog.rust-lang.org/{{url}}" type="text/html" title="{{title}}" />
17+
<published>{{year}}-{{month}}-{{day}}</published>
18+
<id>https://blog.rust-lang.org/{{url}}</id>
19+
<content type="html" xml:base="https://blog.rust-lang.org/{{url}}">{{contents}}</content>
20+
21+
<author>
22+
<name>{{author}}</name>
23+
</author>
24+
</entry>
25+
{{/each}}
26+
</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)