Add subtitles to articles

Fix #152
This commit is contained in:
Bat 2018-09-04 12:26:13 +01:00
parent 7653551d57
commit 94a386ea2c
16 changed files with 63 additions and 8 deletions

View File

@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
ALTER TABLE posts DROP COLUMN subtitle;

View File

@ -0,0 +1,2 @@
-- Your SQL goes here
ALTER TABLE posts ADD COLUMN subtitle TEXT NOT NULL DEFAULT '';

View File

@ -33,7 +33,8 @@ pub struct Post {
pub published: bool, pub published: bool,
pub license: String, pub license: String,
pub creation_date: NaiveDateTime, pub creation_date: NaiveDateTime,
pub ap_url: String pub ap_url: String,
pub subtitle: String,
} }
#[derive(Insertable)] #[derive(Insertable)]
@ -46,7 +47,8 @@ pub struct NewPost {
pub published: bool, pub published: bool,
pub license: String, pub license: String,
pub creation_date: Option<NaiveDateTime>, pub creation_date: Option<NaiveDateTime>,
pub ap_url: String pub ap_url: String,
pub subtitle: String,
} }
impl Post { impl Post {
@ -185,6 +187,7 @@ impl Post {
article.object_props.set_attributed_to_link_vec::<Id>(authors).expect("Article::into_activity: attributedTo error"); article.object_props.set_attributed_to_link_vec::<Id>(authors).expect("Article::into_activity: attributedTo error");
article.object_props.set_content_string(self.content.get().clone()).expect("Article::into_activity: content error"); article.object_props.set_content_string(self.content.get().clone()).expect("Article::into_activity: content error");
article.object_props.set_published_utctime(Utc.from_utc_datetime(&self.creation_date)).expect("Article::into_activity: published error"); article.object_props.set_published_utctime(Utc.from_utc_datetime(&self.creation_date)).expect("Article::into_activity: published error");
article.object_props.set_summary_string(self.subtitle.clone()).expect("Article::into_activity: summary error");
article.object_props.set_tag_link_vec(mentions).expect("Article::into_activity: tag error"); article.object_props.set_tag_link_vec(mentions).expect("Article::into_activity: tag error");
article.object_props.set_url_string(self.ap_url.clone()).expect("Article::into_activity: url error"); article.object_props.set_url_string(self.ap_url.clone()).expect("Article::into_activity: url error");
article.object_props.set_to_link_vec::<Id>(to.into_iter().map(Id::new).collect()).expect("Article::into_activity: to error"); article.object_props.set_to_link_vec::<Id>(to.into_iter().map(Id::new).collect()).expect("Article::into_activity: to error");
@ -250,7 +253,8 @@ impl FromActivity<Article, PgConnection> for Post {
license: String::from("CC-0"), // TODO license: String::from("CC-0"), // TODO
// FIXME: This is wrong: with this logic, we may use the display URL as the AP ID. We need two different fields // FIXME: This is wrong: with this logic, we may use the display URL as the AP ID. We need two different fields
ap_url: article.object_props.url_string().unwrap_or(article.object_props.id_string().expect("Post::from_activity: url + id error")), ap_url: article.object_props.url_string().unwrap_or(article.object_props.id_string().expect("Post::from_activity: url + id error")),
creation_date: Some(article.object_props.published_utctime().expect("Post::from_activity: published error").naive_utc()) creation_date: Some(article.object_props.published_utctime().expect("Post::from_activity: published error").naive_utc()),
subtitle: article.object_props.summary_string().expect("Post::from_activity: summary error")
}); });
for author in authors.into_iter() { for author in authors.into_iter() {

View File

@ -125,6 +125,7 @@ table! {
license -> Varchar, license -> Varchar,
creation_date -> Timestamp, creation_date -> Timestamp,
ap_url -> Varchar, ap_url -> Varchar,
subtitle -> Text,
} }
} }

View File

@ -508,5 +508,9 @@ msgid ""
"Sorry, but registrations are closed on this instance. Try to find another one" "Sorry, but registrations are closed on this instance. Try to find another one"
msgstr "" msgstr ""
#, fuzzy
msgid "Subtitle"
msgstr "Titel"
#~ msgid "Your password should be at least 8 characters long" #~ msgid "Your password should be at least 8 characters long"
#~ msgstr "Das Passwort sollte mindestens 8 Zeichen lang sein" #~ msgstr "Das Passwort sollte mindestens 8 Zeichen lang sein"

View File

@ -497,3 +497,6 @@ msgstr ""
msgid "" msgid ""
"Sorry, but registrations are closed on this instance. Try to find another one" "Sorry, but registrations are closed on this instance. Try to find another one"
msgstr "" msgstr ""
msgid "Subtitle"
msgstr ""

View File

@ -503,4 +503,10 @@ msgstr "Envoyer"
msgid "" msgid ""
"Sorry, but registrations are closed on this instance. Try to find another one" "Sorry, but registrations are closed on this instance. Try to find another one"
msgstr "Désolé, mais les inscriptions sont fermées sur cette instance. Essayez d'en trouver une autre." msgstr ""
"Désolé, mais les inscriptions sont fermées sur cette instance. Essayez d'en "
"trouver une autre."
#, fuzzy
msgid "Subtitle"
msgstr "Titre"

View File

@ -496,4 +496,9 @@ msgstr "Enviar"
msgid "" msgid ""
"Sorry, but registrations are closed on this instance. Try to find another one" "Sorry, but registrations are closed on this instance. Try to find another one"
msgstr "" msgstr ""
"Lamentámolo, pero o rexistro en esta instancia está pechado. Inténteo en outra instancia" "Lamentámolo, pero o rexistro en esta instancia está pechado. Inténteo en "
"outra instancia"
#, fuzzy
msgid "Subtitle"
msgstr "Título"

View File

@ -512,6 +512,10 @@ msgid ""
"Sorry, but registrations are closed on this instance. Try to find another one" "Sorry, but registrations are closed on this instance. Try to find another one"
msgstr "" msgstr ""
#, fuzzy
msgid "Subtitle"
msgstr "Tittel"
#~ msgid "One reshare" #~ msgid "One reshare"
#~ msgid_plural "{{ count }} reshares" #~ msgid_plural "{{ count }} reshares"
#~ msgstr[0] "Én deling" #~ msgstr[0] "Én deling"

View File

@ -523,6 +523,10 @@ msgid ""
"Sorry, but registrations are closed on this instance. Try to find another one" "Sorry, but registrations are closed on this instance. Try to find another one"
msgstr "" msgstr ""
#, fuzzy
msgid "Subtitle"
msgstr "Tytuł"
#~ msgid "One reshare" #~ msgid "One reshare"
#~ msgid_plural "{{ count }} reshares" #~ msgid_plural "{{ count }} reshares"
#~ msgstr[0] "Jedno udostępnienie" #~ msgstr[0] "Jedno udostępnienie"

View File

@ -486,3 +486,6 @@ msgstr ""
msgid "Sorry, but registrations are closed on this instance. Try to find another one" msgid "Sorry, but registrations are closed on this instance. Try to find another one"
msgstr "" msgstr ""
msgid "Subtitle"
msgstr ""

View File

@ -98,6 +98,7 @@ fn new(blog: String, user: User, conn: DbConn) -> Template {
struct NewPostForm { struct NewPostForm {
#[validate(custom(function = "valid_slug", message = "Invalid title"))] #[validate(custom(function = "valid_slug", message = "Invalid title"))]
pub title: String, pub title: String,
pub subtitle: String,
pub content: String, pub content: String,
pub license: String pub license: String
} }
@ -150,7 +151,8 @@ fn create(blog_name: String, data: LenientForm<NewPostForm>, user: User, conn: D
Instance::get_local(&*conn).map(|i| i.default_license).unwrap_or(String::from("CC-0")) Instance::get_local(&*conn).map(|i| i.default_license).unwrap_or(String::from("CC-0"))
}, },
ap_url: "".to_string(), ap_url: "".to_string(),
creation_date: None creation_date: None,
subtitle: form.subtitle.clone()
}); });
let post = post.update_ap_url(&*conn); let post = post.update_ap_url(&*conn);
PostAuthor::insert(&*conn, NewPostAuthor { PostAuthor::insert(&*conn, NewPostAuthor {

View File

@ -131,6 +131,13 @@ main h2 {
font-weight: 300; font-weight: 300;
} }
main h2.article {
max-width: 40rem;
margin: 0.5em auto 1em;
color: rgba(36, 36, 36, 0.6);
font-size: 1.25em;
}
/* /*
* == Article == * == Article ==
*/ */

View File

@ -2,7 +2,13 @@
<div class="card"> <div class="card">
<h3><a href="{{ article.url }}">{{ article.post.title }}</a></h3> <h3><a href="{{ article.url }}">{{ article.post.title }}</a></h3>
<main <main
<p>{{ article.post.content | safe | striptags | truncate(length=200) }}</p> <p>
{% if article.post.subtitle | length > 0 %}
{{ article.post.subtitle }}
{% else %}
{{ article.post.content | safe | striptags | truncate(length=200) }}
{% endif %}
</p>
</main> </main>
<p class="author"> <p class="author">
{{ "By {{ link_1 }}{{ link_2 }}{{ link_3 }}{{ name | escape }}{{ link_4 }}" | _( {{ "By {{ link_1 }}{{ link_2 }}{{ link_3 }}{{ name | escape }}{{ link_4 }}" | _(

View File

@ -11,6 +11,7 @@
{% block content %} {% block content %}
<h1 class="article">{{ article.post.title }}</h1> <h1 class="article">{{ article.post.title }}</h1>
<h2 class="article">{{ article.post.subtitle }}</h2>
<p class="article-info"> <p class="article-info">
<span class="author">{{ "Written by {{ link_1 }}{{ url }}{{ link_2 }}{{ name | escape }}{{ link_3 }}" | _( <span class="author">{{ "Written by {{ link_1 }}{{ url }}{{ link_2 }}{{ name | escape }}{{ link_3 }}" | _(
link_1='<a href="/@/', link_1='<a href="/@/',

View File

@ -9,6 +9,7 @@
<h1>{{ "Create a post" | _ }}</h1> <h1>{{ "Create a post" | _ }}</h1>
<form class="new-post" method="post"> <form class="new-post" method="post">
{{ macros::input(name="title", label="Title", errors=errors, form=form, props="required") }} {{ macros::input(name="title", label="Title", errors=errors, form=form, props="required") }}
{{ macros::input(name="subtitle", label="Subtitle", errors=errors, form=form, optional=true) }}
{% if errors is defined and errors.content %} {% if errors is defined and errors.content %}
{% for err in errors.content %} {% for err in errors.content %}