From ff50143c1c61e70c585a61bc5245d8eb1a462083 Mon Sep 17 00:00:00 2001 From: Joseph Nuthalapati Date: Sat, 19 May 2018 10:16:05 +0530 Subject: [PATCH] Display post author and date in the post view Signed-off-by: Joseph Nuthalapati --- src/routes/posts.rs | 12 ++++++++++-- templates/posts/details.tera | 5 +++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/routes/posts.rs b/src/routes/posts.rs index ce63d684..68aec107 100644 --- a/src/routes/posts.rs +++ b/src/routes/posts.rs @@ -20,8 +20,15 @@ use utils; fn details(blog: String, slug: String, conn: DbConn, user: Option) -> Template { let blog = Blog::find_by_fqn(&*conn, blog).unwrap(); let post = Post::find_by_slug(&*conn, slug).unwrap(); - let comments = Comment::find_by_post(&*conn, post.id); + let comments = Comment::find_by_post(&*conn, post.id); + Template::render("posts/details", json!({ + "author": ({ + let author = &post.get_authors(&*conn)[0]; + let mut json = serde_json::to_value(author).unwrap(); + json["fqn"] = serde_json::Value::String(author.get_fqn(&*conn)); + json + }), "post": post, "blog": blog, "comments": comments.into_iter().map(|c| { @@ -33,7 +40,8 @@ fn details(blog: String, slug: String, conn: DbConn, user: Option) -> Temp }).collect::>(), "n_likes": post.get_likes(&*conn).len(), "has_liked": user.clone().map(|u| u.has_liked(&*conn, &post)).unwrap_or(false), - "account": user + "account": user, + "date": &post.creation_date.timestamp() })) } diff --git a/templates/posts/details.tera b/templates/posts/details.tera index 87432486..22ca2c24 100644 --- a/templates/posts/details.tera +++ b/templates/posts/details.tera @@ -9,6 +9,11 @@ {% endblock header %} {% block content %} +

{{ author.display_name }}

+
+ {{ date | date(format="%B %e, %Y") }} +
+

{{ post.title }}

{{ post.content | safe }}