Make it possible to tag articles and display them
This commit is contained in:
parent
2b7a5bee93
commit
5b3eca63e0
|
@ -19,6 +19,7 @@ use likes::Like;
|
||||||
use mentions::Mention;
|
use mentions::Mention;
|
||||||
use post_authors::*;
|
use post_authors::*;
|
||||||
use reshares::Reshare;
|
use reshares::Reshare;
|
||||||
|
use tags::Tag;
|
||||||
use users::User;
|
use users::User;
|
||||||
use schema::posts;
|
use schema::posts;
|
||||||
use safe_string::SafeString;
|
use safe_string::SafeString;
|
||||||
|
@ -244,7 +245,8 @@ impl Post {
|
||||||
"author": self.get_authors(conn)[0].to_json(conn),
|
"author": self.get_authors(conn)[0].to_json(conn),
|
||||||
"url": format!("/~/{}/{}/", blog.get_fqn(conn), self.slug),
|
"url": format!("/~/{}/{}/", blog.get_fqn(conn), self.slug),
|
||||||
"date": self.creation_date.timestamp(),
|
"date": self.creation_date.timestamp(),
|
||||||
"blog": blog.to_json(conn)
|
"blog": blog.to_json(conn),
|
||||||
|
"tags": Tag::for_post(&*conn, self.id)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use diesel::{self, PgConnection, ExpressionMethods, RunQueryDsl, QueryDsl};
|
use diesel::{self, PgConnection, ExpressionMethods, RunQueryDsl, QueryDsl};
|
||||||
use schema::tags;
|
use schema::tags;
|
||||||
|
|
||||||
#[derive(Queryable)]
|
#[derive(Serialize, Queryable)]
|
||||||
pub struct Tag {
|
pub struct Tag {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub tag: String,
|
pub tag: String,
|
||||||
|
@ -20,4 +20,5 @@ pub struct NewTag {
|
||||||
impl Tag {
|
impl Tag {
|
||||||
insert!(tags, NewTag);
|
insert!(tags, NewTag);
|
||||||
get!(tags);
|
get!(tags);
|
||||||
|
list_by!(tags, for_post, post_id as i32);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use activitypub::object::Article;
|
use activitypub::object::Article;
|
||||||
use heck::KebabCase;
|
use heck::{CamelCase, KebabCase};
|
||||||
use rocket::{State, request::LenientForm};
|
use rocket::{State, request::LenientForm};
|
||||||
use rocket::response::{Redirect, Flash};
|
use rocket::response::{Redirect, Flash};
|
||||||
use rocket_contrib::Template;
|
use rocket_contrib::Template;
|
||||||
|
@ -19,6 +19,7 @@ use plume_models::{
|
||||||
post_authors::*,
|
post_authors::*,
|
||||||
posts::*,
|
posts::*,
|
||||||
safe_string::SafeString,
|
safe_string::SafeString,
|
||||||
|
tags::*,
|
||||||
users::User
|
users::User
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -101,6 +102,7 @@ struct NewPostForm {
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub subtitle: String,
|
pub subtitle: String,
|
||||||
pub content: String,
|
pub content: String,
|
||||||
|
pub tags: String,
|
||||||
pub license: String
|
pub license: String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,6 +167,15 @@ fn create(blog_name: String, data: LenientForm<NewPostForm>, user: User, conn: D
|
||||||
Mention::from_activity(&*conn, Mention::build_activity(&*conn, m), post.id, true);
|
Mention::from_activity(&*conn, Mention::build_activity(&*conn, m), post.id, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let tags = form.tags.split(",").map(|t| t.trim().to_camel_case()).filter(|t| t.len() > 0);
|
||||||
|
for tag in tags {
|
||||||
|
Tag::insert(&*conn, NewTag {
|
||||||
|
tag: tag,
|
||||||
|
is_hastag: false,
|
||||||
|
post_id: post.id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let act = post.create_activity(&*conn);
|
let act = post.create_activity(&*conn);
|
||||||
let followers = user.get_followers(&*conn);
|
let followers = user.get_followers(&*conn);
|
||||||
worker.execute(Thunk::of(move || broadcast(&user, act, followers)));
|
worker.execute(Thunk::of(move || broadcast(&user, act, followers)));
|
||||||
|
|
|
@ -217,10 +217,27 @@
|
||||||
}
|
}
|
||||||
main .article-meta > * { margin: 0 20%; }
|
main .article-meta > * { margin: 0 20%; }
|
||||||
|
|
||||||
main .article-meta > p {
|
main .article-meta > p {
|
||||||
margin: 2em 20%;
|
margin: 2em 20%;
|
||||||
font-size: 0.9em;
|
font-size: 0.9em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Tags **/
|
||||||
|
|
||||||
|
main .article-meta .tags {
|
||||||
|
list-style: none;
|
||||||
|
display: inline-block;
|
||||||
|
padding: 0px;
|
||||||
|
margin-bottom: 2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
main .article-meta .tags li {
|
||||||
|
display: inline;
|
||||||
|
background: #DADADA;
|
||||||
|
padding: 10px 20px;
|
||||||
|
margin-right: 10px;
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
/* ~ Likes ~ */
|
/* ~ Likes ~ */
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,11 @@
|
||||||
|
|
||||||
<div class="article-meta">
|
<div class="article-meta">
|
||||||
<p>{{ "This article is under the {{ license }} license." | _(license=article.post.license) }}</p>
|
<p>{{ "This article is under the {{ license }} license." | _(license=article.post.license) }}</p>
|
||||||
|
<ul class="tags">
|
||||||
|
{% for tag in article.tags %}
|
||||||
|
<li>{{ tag.tag }}</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<img src="{{ author.avatar }}" alt="{{ author.name }}" class="avatar medium padded">
|
<img src="{{ author.avatar }}" alt="{{ author.name }}" class="avatar medium padded">
|
||||||
<div class="grow">
|
<div class="grow">
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
<label for="content">{{ "Content" | _ }}<small>{{ "Markdown is supported" | _ }}</small></label>
|
<label for="content">{{ "Content" | _ }}<small>{{ "Markdown is supported" | _ }}</small></label>
|
||||||
<textarea id="content" name="content" value="{{ form.content | default(value="") }}" rows="20"></textarea>
|
<textarea id="content" name="content" value="{{ form.content | default(value="") }}" rows="20"></textarea>
|
||||||
|
|
||||||
|
{{ macros::input(name="tags", label="Tags, separated by commas", errors=errors, form=form, optional=true) }}
|
||||||
|
|
||||||
{% set license_infos = "Default license will be {{ instance.default_license }}" | _(instance=instance) %}
|
{% set license_infos = "Default license will be {{ instance.default_license }}" | _(instance=instance) %}
|
||||||
{{ macros::input(name="license", label="License", errors=errors, form=form, optional=true, details=license_infos) }}
|
{{ macros::input(name="license", label="License", errors=errors, form=form, optional=true, details=license_infos) }}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue