Add some to_json functions to models for serialization in templates

This commit is contained in:
Bat
2018-06-18 17:34:29 +01:00
parent 58cc35691d
commit 7e3cdec0b6
7 changed files with 28 additions and 77 deletions
+1 -13
View File
@@ -22,19 +22,7 @@ fn index(conn: DbConn, user: Option<User>) -> Template {
Template::render("instance/index", json!({
"instance": inst,
"account": user,
"recents": recents.into_iter().map(|p| {
json!({
"post": p,
"author": ({
let author = &p.get_authors(&*conn)[0];
let mut json = serde_json::to_value(author).unwrap();
json["fqn"] = serde_json::Value::String(author.get_fqn(&*conn));
json
}),
"url": format!("/~/{}/{}/", p.get_blog(&*conn).actor_id, p.slug),
"date": p.creation_date.timestamp()
})
}).collect::<Vec<serde_json::Value>>()
"recents": recents.into_iter().map(|p| p.to_json(&*conn)).collect::<Vec<serde_json::Value>>()
}))
}
None => {