Kaynağa Gözat

Allow displaying date

master
Dylan Baker 5 yıl önce
ebeveyn
işleme
bb7592eac1
2 değiştirilmiş dosya ile 10 ekleme ve 6 silme
  1. 2
    2
      src/commands.rs
  2. 8
    4
      src/render.rs

+ 2
- 2
src/commands.rs Dosyayı Görüntüle

150
     );
150
     );
151
     let default_post_listing_item_template = format!(
151
     let default_post_listing_item_template = format!(
152
         "<li>
152
         "<li>
153
-  <a href=\"/posts/{{{{ slug }}}}/\">{{{{ title }}}}</a>
153
+  {{ date }} <a href=\"/posts/{{{{ slug }}}}/\">{{{{ title }}}}</a>
154
 </li>\n"
154
 </li>\n"
155
     );
155
     );
156
 
156
 
247
                 .replace("  ", "")
247
                 .replace("  ", "")
248
         );
248
         );
249
         assert_eq!(
249
         assert_eq!(
250
-            format!("<li><a href=\"/posts/{{{{ slug }}}}/\">{{{{ title }}}}</a></li>"),
250
+            format!("<li>{{ date }} <a href=\"/posts/{{{{ slug }}}}/\">{{{{ title }}}}</a></li>"),
251
             fs::read_to_string(&project_dir.join("templates").join("post_listing_item.html"))
251
             fs::read_to_string(&project_dir.join("templates").join("post_listing_item.html"))
252
                 .unwrap()
252
                 .unwrap()
253
                 .replace("\n", "")
253
                 .replace("\n", "")

+ 8
- 4
src/render.rs Dosyayı Görüntüle

12
         )
12
         )
13
         .replace(
13
         .replace(
14
             "{{ contents }}",
14
             "{{ contents }}",
15
-            &post_template.replace("{{ title }}", &post.title).replace(
16
-                "{{ body }}",
17
-                &markdown_to_html(&post.body, &ComrakOptions::default()),
18
-            ),
15
+            &post_template
16
+                .replace("{{ title }}", &post.title)
17
+                .replace(
18
+                    "{{ body }}",
19
+                    &markdown_to_html(&post.body, &ComrakOptions::default()),
20
+                )
21
+                .replace("{{ date }}", &post.date.format("%Y-%m-%d").to_string()),
19
         )
22
         )
20
 }
23
 }
21
 
24
 
53
                         post_item_template
56
                         post_item_template
54
                             .replace("{{ slug }}", &post.slug)
57
                             .replace("{{ slug }}", &post.slug)
55
                             .replace("{{ title }}", &post.title)
58
                             .replace("{{ title }}", &post.title)
59
+                            .replace("{{ date }}", &post.date.format("%Y-%m-%d").to_string())
56
                     })
60
                     })
57
                     .collect::<Vec<String>>()
61
                     .collect::<Vec<String>>()
58
                     .join("\n"),
62
                     .join("\n"),

Loading…
İptal
Kaydet