Add some to_json functions to models for serialization in templates
This commit is contained in:
+1
-13
@@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user