Переглянути джерело

Read post listing item from template

master
Dylan Baker 5 роки тому
джерело
коміт
22fc62f537
1 змінених файлів з 8 додано та 2 видалено
  1. 8
    2
      src/main.rs

+ 8
- 2
src/main.rs Переглянути файл

@@ -66,10 +66,16 @@ fn render_post(cwd: &path::PathBuf, layout: &str, post: &Post) {
66 66
 }
67 67
 
68 68
 fn render_post_listing(cwd: &path::PathBuf, layout: &str, posts: &Vec<Post>) {
69
+    let post_item_template =
70
+        fs::read_to_string(cwd.join("templates").join("post_listing_item.html"))
71
+            .expect("Couldn't find post listing item template");
69 72
     let post_listing = posts
70 73
         .iter()
71
-        .map(|ref post| format!("<li><a href='/{}/'>{}</a></li>", post.slug, post.title))
72
-        .collect::<Vec<String>>()
74
+        .map(|ref post| {
75
+            post_item_template
76
+                .replace("{{ slug }}", &post.slug)
77
+                .replace("{{ title }}", &post.title)
78
+        }).collect::<Vec<String>>()
73 79
         .join("\n");
74 80
 
75 81
     let output = layout.replace("{{ contents }}", &post_listing);

Завантаження…
Відмінити
Зберегти