From 89713526e2401b4210aba537a0e72966a3688ca0 Mon Sep 17 00:00:00 2001
From: "Kevin \"Ilphrin\" Pellet"
Date: Sun, 22 Jul 2018 01:42:27 +0200
Subject: [PATCH 1/3] Add a link to the blog on article cards
Fixes #134
---
plume-models/src/posts.rs | 7 +++++--
templates/macros.html.tera | 1 +
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/plume-models/src/posts.rs b/plume-models/src/posts.rs
index 5a04b9f8..22f02442 100644
--- a/plume-models/src/posts.rs
+++ b/plume-models/src/posts.rs
@@ -181,11 +181,14 @@ impl Post {
}
pub fn to_json(&self, conn: &PgConnection) -> serde_json::Value {
+ let blog = self.get_blog(conn);
json!({
"post": self,
"author": self.get_authors(conn)[0].to_json(conn),
- "url": format!("/~/{}/{}/", self.get_blog(conn).actor_id, self.slug),
- "date": self.creation_date.timestamp()
+ "url": format!("/~/{}/{}/", blog.actor_id, self.slug),
+ "date": self.creation_date.timestamp(),
+ "blog": blog,
+ "blog_url": format!("/~/{}", blog.actor_id)
})
}
diff --git a/templates/macros.html.tera b/templates/macros.html.tera
index d474a6be..62d90dc3 100644
--- a/templates/macros.html.tera
+++ b/templates/macros.html.tera
@@ -18,6 +18,7 @@
link_4="")
}}
⋅ {{ article.date | date(format="%B %e") }}
+ ⋅ {{article.blog.title}}
{% endmacro post_card %}
From 390d694cac26ec7eb673424ae731706b0c32568a Mon Sep 17 00:00:00 2001
From: "Kevin \"Ilphrin\" Pellet"
Date: Wed, 25 Jul 2018 21:21:47 +0200
Subject: [PATCH 2/3] Fix styling and field values
---
templates/macros.html.tera | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/templates/macros.html.tera b/templates/macros.html.tera
index 62d90dc3..eadc13d2 100644
--- a/templates/macros.html.tera
+++ b/templates/macros.html.tera
@@ -18,7 +18,7 @@
link_4="")
}}
⋅ {{ article.date | date(format="%B %e") }}
- ⋅ {{article.blog.title}}
+ ⋅ {{ article.blog.title }}
{% endmacro post_card %}
From aaae786fb73687dfccbd91e904ccdd55ac3fed3e Mon Sep 17 00:00:00 2001
From: "Kevin \"Ilphrin\" Pellet"
Date: Wed, 25 Jul 2018 21:22:42 +0200
Subject: [PATCH 3/3] Implement new function to Blog for the view
Added Blog::to_json and Blog::get_fqn
---
plume-models/src/blogs.rs | 15 +++++++++++++++
plume-models/src/posts.rs | 3 +--
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/plume-models/src/blogs.rs b/plume-models/src/blogs.rs
index 7123d36a..59991be6 100644
--- a/plume-models/src/blogs.rs
+++ b/plume-models/src/blogs.rs
@@ -248,6 +248,21 @@ impl Blog {
}
})
}
+
+ pub fn get_fqn(&self, conn: &PgConnection) -> String {
+ if self.instance_id == Instance::local_id(conn) {
+ self.actor_id.clone()
+ } else {
+ format!("{}@{}", self.actor_id, self.get_instance(conn).public_domain)
+ }
+ }
+
+ pub fn to_json(&self, conn: &PgConnection) -> serde_json::Value {
+ let mut json = serde_json::to_value(self).unwrap();
+ let formatted = serde_json::Value::String(format!("/~/{}",self.get_fqn(conn)));
+ json["fqn"] = formatted;
+ json
+ }
}
impl IntoId for Blog {
diff --git a/plume-models/src/posts.rs b/plume-models/src/posts.rs
index 22f02442..3c0f1eb1 100644
--- a/plume-models/src/posts.rs
+++ b/plume-models/src/posts.rs
@@ -187,8 +187,7 @@ impl Post {
"author": self.get_authors(conn)[0].to_json(conn),
"url": format!("/~/{}/{}/", blog.actor_id, self.slug),
"date": self.creation_date.timestamp(),
- "blog": blog,
- "blog_url": format!("/~/{}", blog.actor_id)
+ "blog": blog.to_json(conn)
})
}