Add a link to author's profile on article card
Use a macro to render those cards too
This commit is contained in:
parent
5e7d513a7e
commit
91b19bccb5
@ -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<User> {
|
||||
|
@ -24,7 +24,12 @@ fn details(name: String, conn: DbConn, user: Option<User>) -> 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()
|
||||
})
|
||||
|
@ -21,7 +21,12 @@ fn index(conn: DbConn, user: Option<User>) -> 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()
|
||||
})
|
||||
|
@ -31,7 +31,12 @@ fn details(name: String, conn: DbConn, account: Option<User>) -> 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()
|
||||
})
|
||||
|
@ -1,4 +1,5 @@
|
||||
{% extends "base" %}
|
||||
{% import "macros" as macros %}
|
||||
|
||||
{% block title %}
|
||||
{{ blog.title }}
|
||||
@ -10,10 +11,6 @@
|
||||
|
||||
<h2>Latest articles</h2>
|
||||
{% for article in recents %}
|
||||
<div>
|
||||
<h3><a href="{{ article.url }}">{{ article.post.title }}</a></h3>
|
||||
<p>{{ article.post.content | escape | truncate(length=200) }}…</p>
|
||||
<p>By {{ article.author.display_name }} ⋅ {{ article.date | date(format="%B %e") }}</p>
|
||||
</div>
|
||||
{{ macros::post_card(article=article) }}
|
||||
{% endfor %}
|
||||
{% endblock content %}
|
||||
|
@ -1,4 +1,5 @@
|
||||
{% extends "base" %}
|
||||
{% import "macros" as macros %}
|
||||
|
||||
{% block title %}
|
||||
{{ instance.name }}
|
||||
@ -9,10 +10,6 @@
|
||||
|
||||
<h2>Latest articles</h2>
|
||||
{% for article in recents %}
|
||||
<div>
|
||||
<h3><a href="{{ article.url }}">{{ article.post.title }}</a></h3>
|
||||
<p>{{ article.post.content | escape | truncate(length=200) }}…</p>
|
||||
<p>By {{ article.author.display_name }} ⋅ {{ article.date | date(format="%B %e") }}</p>
|
||||
</div>
|
||||
{{ macros::post_card(article=article) }}
|
||||
{% endfor %}
|
||||
{% endblock content %}
|
||||
|
7
templates/macros.tera
Normal file
7
templates/macros.tera
Normal file
@ -0,0 +1,7 @@
|
||||
{% macro post_card(article) %}
|
||||
<div>
|
||||
<h3><a href="{{ article.url }}">{{ article.post.title }}</a></h3>
|
||||
<p>{{ article.post.content | escape | truncate(length=200) }}…</p>
|
||||
<p>By <a href="/@/{{ article.author.fqn }}/">{{ article.author.display_name }}</a> ⋅ {{ article.date | date(format="%B %e") }}</p>
|
||||
</div>
|
||||
{% endmacro post_card %}
|
@ -1,4 +1,5 @@
|
||||
{% extends "base" %}
|
||||
{% import "macros" as macros %}
|
||||
|
||||
{% block title %}
|
||||
{{ user.display_name }}
|
||||
@ -32,10 +33,6 @@
|
||||
|
||||
<h2>Latest articles</h2>
|
||||
{% for article in recents %}
|
||||
<div>
|
||||
<h3><a href="{{ article.url }}">{{ article.post.title }}</a></h3>
|
||||
<p>{{ article.post.content | escape | truncate(length=200) }}…</p>
|
||||
<p>By {{ article.author.display_name }} ⋅ {{ article.date | date(format="%B %e") }}</p>
|
||||
</div>
|
||||
{{ macros::post_card(article=article) }}
|
||||
{% endfor %}
|
||||
{% endblock content %}
|
||||
|
Loading…
Reference in New Issue
Block a user