Add a button to write a new article
This commit is contained in:
parent
edbeeef640
commit
7fd152e270
@ -35,6 +35,8 @@ use activity_pub::{
|
|||||||
};
|
};
|
||||||
use db_conn::DbConn;
|
use db_conn::DbConn;
|
||||||
use models::{
|
use models::{
|
||||||
|
blogs::Blog,
|
||||||
|
blog_authors::BlogAuthor,
|
||||||
comments::Comment,
|
comments::Comment,
|
||||||
follows::Follow,
|
follows::Follow,
|
||||||
instance::Instance,
|
instance::Instance,
|
||||||
@ -297,6 +299,15 @@ impl User {
|
|||||||
.len() > 0
|
.len() > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_author_in(&self, conn: &PgConnection, blog: Blog) -> bool {
|
||||||
|
use schema::blog_authors;
|
||||||
|
blog_authors::table.filter(blog_authors::author_id.eq(self.id))
|
||||||
|
.filter(blog_authors::blog_id.eq(blog.id))
|
||||||
|
.load::<BlogAuthor>(conn)
|
||||||
|
.expect("Couldn't load blog/author relationship")
|
||||||
|
.len() > 0
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_keypair(&self) -> PKey<Private> {
|
pub fn get_keypair(&self) -> PKey<Private> {
|
||||||
PKey::from_rsa(Rsa::private_key_from_pem(self.private_key.clone().unwrap().as_ref()).unwrap()).unwrap()
|
PKey::from_rsa(Rsa::private_key_from_pem(self.private_key.clone().unwrap().as_ref()).unwrap()).unwrap()
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ fn details(name: String, conn: DbConn, user: Option<User>) -> Template {
|
|||||||
Template::render("blogs/details", json!({
|
Template::render("blogs/details", json!({
|
||||||
"blog": blog,
|
"blog": blog,
|
||||||
"account": user,
|
"account": user,
|
||||||
|
"is_author": user.map(|x| x.is_author_in(&*conn, blog)),
|
||||||
"recents": recents.into_iter().map(|p| {
|
"recents": recents.into_iter().map(|p| {
|
||||||
json!({
|
json!({
|
||||||
"post": p,
|
"post": p,
|
||||||
|
@ -9,10 +9,18 @@
|
|||||||
<h1>{{ blog.title }} (~{{ blog.actor_id }})</h1>
|
<h1>{{ blog.title }} (~{{ blog.actor_id }})</h1>
|
||||||
<p>{{ blog.summary }}</p>
|
<p>{{ blog.summary }}</p>
|
||||||
|
|
||||||
|
<section>
|
||||||
<h2>Latest articles</h2>
|
<h2>Latest articles</h2>
|
||||||
|
{% if recents | length < 1 %}
|
||||||
|
<p>No posts to see here yet.</p>
|
||||||
|
{% endif %}
|
||||||
|
{% if is_author %}
|
||||||
|
<a href="new" class="button inline-block">New article</a>
|
||||||
|
{% endif %}
|
||||||
<div class="cards">
|
<div class="cards">
|
||||||
{% for article in recents %}
|
{% for article in recents %}
|
||||||
{{ macros::post_card(article=article) }}
|
{{ macros::post_card(article=article) }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
</section>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
Loading…
Reference in New Issue
Block a user