Skip to content

Commit bdd0a95

Browse files
committed
add in other required feed elements
1 parent f672f55 commit bdd0a95

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/main.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct Post {
3131
day: String,
3232
contents: String,
3333
url: String,
34+
published: String,
3435
}
3536

3637
#[derive(Debug, PartialEq, Serialize, Deserialize)]
@@ -125,6 +126,25 @@ impl Blog {
125126

126127
// this is fine
127128
let url = format!("{}/{}/{}/{}", year, month, day, url.to_str().unwrap());
129+
130+
// build the published time. this is only approximate, which is fine.
131+
// we do some unwraps because these need to be valid
132+
let published = time::Tm {
133+
tm_sec: 0,
134+
tm_min: 0,
135+
tm_hour: 0,
136+
tm_mday: day.parse::<i32>().unwrap(),
137+
tm_mon: month.parse::<i32>().unwrap() - 1, // 0-11 not 1-12
138+
tm_year: year.parse::<i32>().unwrap() - 1900, // from the year 1900, not the actual year
139+
// these next two fields are wrong but we never use them to generate our times
140+
tm_wday: 1,
141+
tm_yday: 1,
142+
tm_isdst: 0,
143+
tm_utcoff: 0,
144+
tm_nsec: 0,
145+
};
146+
147+
let published = published.rfc3339().to_string();
128148

129149
let post = Post {
130150
filename,
@@ -136,6 +156,7 @@ impl Blog {
136156
day,
137157
contents,
138158
url,
159+
published,
139160
};
140161

141162
posts.push(post);

templates/feed.hbs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<generator uri="https://blog.rust-lang.org/" version="0.1.0">Rust Blog</generator>
44
<link href="https://blog.rust-lang.org/feed.xml" rel="self" type="application/atom+xml" />
55
<link href="https://blog.rust-lang.org/" rel="alternate" type="text/html" />
6+
<id>https://blog.rust-lang.org/</id>
67
<title>Rust Blog</title>
78
<subtitle>Empowering everyone to build reliable and efficient software.</subtitle>
89
<author>
@@ -15,7 +16,8 @@
1516
<entry>
1617
<title>{{title}}</title>
1718
<link rel="alternate" href="https://blog.rust-lang.org/{{url}}" type="text/html" title="{{title}}" />
18-
<published>{{year}}-{{month}}-{{day}}</published>
19+
<published>{{ published }}</published>
20+
<updated>{{ published }}</updated>
1921
<id>https://blog.rust-lang.org/{{url}}</id>
2022
<content type="html" xml:base="https://blog.rust-lang.org/{{url}}">{{contents}}</content>
2123

0 commit comments

Comments
 (0)