diff --git a/src/models/users.rs b/src/models/users.rs index 6d16165d..a62d3c65 100644 --- a/src/models/users.rs +++ b/src/models/users.rs @@ -227,7 +227,11 @@ impl User { } pub fn get_fqn(&self, conn: &PgConnection) -> String { - format!("{}@{}", self.username, self.get_instance(conn).public_domain) + if self.instance_id == Instance::local_id(conn) { + self.username.clone() + } else { + format!("{}@{}", self.username, self.get_instance(conn).public_domain) + } } pub fn get_followers(&self, conn: &PgConnection) -> Vec { diff --git a/src/routes/blogs.rs b/src/routes/blogs.rs index f5513042..16f8912e 100644 --- a/src/routes/blogs.rs +++ b/src/routes/blogs.rs @@ -24,7 +24,12 @@ fn details(name: String, conn: DbConn, user: Option) -> Template { "recents": recents.into_iter().map(|p| { json!({ "post": p, - "author": p.get_authors(&*conn)[0], + "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() }) diff --git a/src/routes/instance.rs b/src/routes/instance.rs index f6ff3841..6b4bbb45 100644 --- a/src/routes/instance.rs +++ b/src/routes/instance.rs @@ -21,7 +21,12 @@ fn index(conn: DbConn, user: Option) -> Template { "recents": recents.into_iter().map(|p| { json!({ "post": p, - "author": p.get_authors(&*conn)[0], + "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() }) diff --git a/src/routes/user.rs b/src/routes/user.rs index 2f053f47..8e3a93ce 100644 --- a/src/routes/user.rs +++ b/src/routes/user.rs @@ -31,7 +31,12 @@ fn details(name: String, conn: DbConn, account: Option) -> Template { "recents": recents.into_iter().map(|p| { json!({ "post": p, - "author": p.get_authors(&*conn)[0], + "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() }) diff --git a/templates/blogs/details.tera b/templates/blogs/details.tera index 6274c4f7..1f74d5f0 100644 --- a/templates/blogs/details.tera +++ b/templates/blogs/details.tera @@ -1,4 +1,5 @@ {% extends "base" %} +{% import "macros" as macros %} {% block title %} {{ blog.title }} @@ -10,10 +11,6 @@

Latest articles

{% for article in recents %} -
-

{{ article.post.title }}

-

{{ article.post.content | escape | truncate(length=200) }}…

-

By {{ article.author.display_name }} ⋅ {{ article.date | date(format="%B %e") }}

-
+ {{ macros::post_card(article=article) }} {% endfor %} {% endblock content %} diff --git a/templates/instance/index.tera b/templates/instance/index.tera index 8090ead0..ccb07fb3 100644 --- a/templates/instance/index.tera +++ b/templates/instance/index.tera @@ -1,4 +1,5 @@ {% extends "base" %} +{% import "macros" as macros %} {% block title %} {{ instance.name }} @@ -9,10 +10,6 @@

Latest articles

{% for article in recents %} -
-

{{ article.post.title }}

-

{{ article.post.content | escape | truncate(length=200) }}…

-

By {{ article.author.display_name }} ⋅ {{ article.date | date(format="%B %e") }}

-
+ {{ macros::post_card(article=article) }} {% endfor %} {% endblock content %} diff --git a/templates/macros.tera b/templates/macros.tera new file mode 100644 index 00000000..a8278987 --- /dev/null +++ b/templates/macros.tera @@ -0,0 +1,7 @@ +{% macro post_card(article) %} +
+

{{ article.post.title }}

+

{{ article.post.content | escape | truncate(length=200) }}…

+

By {{ article.author.display_name }} ⋅ {{ article.date | date(format="%B %e") }}

+
+{% endmacro post_card %} diff --git a/templates/users/details.tera b/templates/users/details.tera index d48bb17b..8290bde5 100644 --- a/templates/users/details.tera +++ b/templates/users/details.tera @@ -1,4 +1,5 @@ {% extends "base" %} +{% import "macros" as macros %} {% block title %} {{ user.display_name }} @@ -32,10 +33,6 @@

Latest articles

{% for article in recents %} -
-

{{ article.post.title }}

-

{{ article.post.content | escape | truncate(length=200) }}…

-

By {{ article.author.display_name }} ⋅ {{ article.date | date(format="%B %e") }}

-
+ {{ macros::post_card(article=article) }} {% endfor %} {% endblock content %}