|
@@ -70,14 +70,19 @@ fn render_post_listing(
|
70
|
70
|
post_item_template: &str,
|
71
|
71
|
posts: &Vec<Post>,
|
72
|
72
|
) {
|
73
|
|
- let post_listing = posts
|
74
|
|
- .iter()
|
75
|
|
- .map(|ref post| {
|
76
|
|
- post_item_template
|
77
|
|
- .replace("{{ slug }}", &post.slug)
|
78
|
|
- .replace("{{ title }}", &post.title)
|
79
|
|
- }).collect::<Vec<String>>()
|
80
|
|
- .join("\n");
|
|
73
|
+ let post_listing_template = fs::read_to_string(cwd.join("templates").join("index.html"))
|
|
74
|
+ .expect("Couldn't read templates/index.html");
|
|
75
|
+ let post_listing = post_listing_template.replace(
|
|
76
|
+ "{{ post_listing }}",
|
|
77
|
+ &posts
|
|
78
|
+ .iter()
|
|
79
|
+ .map(|ref post| {
|
|
80
|
+ post_item_template
|
|
81
|
+ .replace("{{ slug }}", &post.slug)
|
|
82
|
+ .replace("{{ title }}", &post.title)
|
|
83
|
+ }).collect::<Vec<String>>()
|
|
84
|
+ .join("\n"),
|
|
85
|
+ );
|
81
|
86
|
|
82
|
87
|
let output = layout.replace("{{ contents }}", &post_listing);
|
83
|
88
|
fs::write(cwd.join("public").join("index.html"), &output).expect("Unable to write file");
|