diff --git a/src/routes/comments.rs b/src/routes/comments.rs index fab683cc..4e956646 100644 --- a/src/routes/comments.rs +++ b/src/routes/comments.rs @@ -21,11 +21,11 @@ struct NewCommentForm { pub respond_to: Option } -#[post("/~/<_blog>//comment", data = "")] -fn create(_blog: String, slug: String, data: Form, user: User, conn: DbConn) -> Redirect { - let post = Post::find_by_slug(&*conn, slug).unwrap(); +#[post("/~///comment", data = "")] +fn create(blog: String, slug: String, data: Form, user: User, conn: DbConn) -> Redirect { + let post = Post::find_by_slug(&*conn, slug.clone()).unwrap(); let form = data.get(); - Comment::insert(&*conn, NewComment { + let comment = Comment::insert(&*conn, NewComment { content: form.content.clone(), in_response_to_id: form.respond_to, post_id: post.id, @@ -34,5 +34,5 @@ fn create(_blog: String, slug: String, data: Form, user: User, c sensitive: false, spoiler_text: "".to_string() }); - Redirect::to("") + Redirect::to(format!("/~/{}/{}/#comment-{}", blog, slug, comment.id).as_ref()) } diff --git a/src/routes/posts.rs b/src/routes/posts.rs index e039e04f..dd9f2b73 100644 --- a/src/routes/posts.rs +++ b/src/routes/posts.rs @@ -27,6 +27,7 @@ fn details(blog: String, slug: String, conn: DbConn) -> Template { "blog": blog, "comments": comments.into_iter().map(|c| { json!({ + "id": c.id, "content": c.content, "author": c.get_author(&*conn) }) diff --git a/templates/posts/details.tera b/templates/posts/details.tera index 71cc1712..ea7570ea 100644 --- a/templates/posts/details.tera +++ b/templates/posts/details.tera @@ -15,7 +15,7 @@

Comments

{% for comment in comments %} -
+
{{ comment.author.display_name }}
{{ comment.content | safe }}