Browse Source

Allow displaying date

master
Dylan Baker 5 years ago
parent
commit
bb7592eac1
2 changed files with 10 additions and 6 deletions
  1. 2
    2
      src/commands.rs
  2. 8
    4
      src/render.rs

+ 2
- 2
src/commands.rs View File

@@ -150,7 +150,7 @@ pub fn new(name: &str) {
150 150
     );
151 151
     let default_post_listing_item_template = format!(
152 152
         "<li>
153
-  <a href=\"/posts/{{{{ slug }}}}/\">{{{{ title }}}}</a>
153
+  {{ date }} <a href=\"/posts/{{{{ slug }}}}/\">{{{{ title }}}}</a>
154 154
 </li>\n"
155 155
     );
156 156
 
@@ -247,7 +247,7 @@ mod tests {
247 247
                 .replace("  ", "")
248 248
         );
249 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 251
             fs::read_to_string(&project_dir.join("templates").join("post_listing_item.html"))
252 252
                 .unwrap()
253 253
                 .replace("\n", "")

+ 8
- 4
src/render.rs View File

@@ -12,10 +12,13 @@ pub fn render_post(layout: &str, post_template: &str, post: &Post, config: &Conf
12 12
         )
13 13
         .replace(
14 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,6 +56,7 @@ pub fn render_post_listing(
53 56
                         post_item_template
54 57
                             .replace("{{ slug }}", &post.slug)
55 58
                             .replace("{{ title }}", &post.title)
59
+                            .replace("{{ date }}", &post.date.format("%Y-%m-%d").to_string())
56 60
                     })
57 61
                     .collect::<Vec<String>>()
58 62
                     .join("\n"),

Loading…
Cancel
Save