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,20 +33,22 @@ pub struct Post {
pub published: bool,
pub license: String,
pub creation_date: NaiveDateTime,
pub ap_url: String
pub ap_url: String,
pub subtitle: String,
}
#[derive(Insertable)]
#[table_name = "posts"]
pub struct NewPost {
pub blog_id: i32,
pub blog_id: i32,
pub slug: String,
pub title: String,
pub content: SafeString,
pub published: bool,
pub license: String,
pub creation_date: Option<NaiveDateTime>,
pub ap_url: String
pub ap_url: String,
pub subtitle: String,
}
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_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_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_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");
@ -250,7 +253,8 @@ impl FromActivity<Article, PgConnection> for Post {
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
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() {

View file

@ -125,6 +125,7 @@ table! {
license -> Varchar,
creation_date -> Timestamp,
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"
msgstr ""
#, fuzzy
msgid "Subtitle"
msgstr "Titel"
#~ msgid "Your password should be at least 8 characters long"
#~ msgstr "Das Passwort sollte mindestens 8 Zeichen lang sein"

View file

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

View file

@ -503,4 +503,10 @@ msgstr "Envoyer"
msgid ""
"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 ""
"Sorry, but registrations are closed on this instance. Try to find another one"
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"
msgstr ""
#, fuzzy
msgid "Subtitle"
msgstr "Tittel"
#~ msgid "One reshare"
#~ msgid_plural "{{ count }} reshares"
#~ msgstr[0] "Én deling"

View file

@ -523,6 +523,10 @@ msgid ""
"Sorry, but registrations are closed on this instance. Try to find another one"
msgstr ""
#, fuzzy
msgid "Subtitle"
msgstr "Tytuł"
#~ msgid "One reshare"
#~ msgid_plural "{{ count }} reshares"
#~ 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"
msgstr ""
msgid "Subtitle"
msgstr ""

View file

@ -98,6 +98,7 @@ fn new(blog: String, user: User, conn: DbConn) -> Template {
struct NewPostForm {
#[validate(custom(function = "valid_slug", message = "Invalid title"))]
pub title: String,
pub subtitle: String,
pub content: 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"))
},
ap_url: "".to_string(),
creation_date: None
creation_date: None,
subtitle: form.subtitle.clone()
});
let post = post.update_ap_url(&*conn);
PostAuthor::insert(&*conn, NewPostAuthor {

View file

@ -131,6 +131,13 @@ main h2 {
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 ==
*/

View file

@ -2,7 +2,13 @@
<div class="card">
<h3><a href="{{ article.url }}">{{ article.post.title }}</a></h3>
<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>
<p class="author">
{{ "By {{ link_1 }}{{ link_2 }}{{ link_3 }}{{ name | escape }}{{ link_4 }}" | _(

View file

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

View file

@ -9,6 +9,7 @@
<h1>{{ "Create a post" | _ }}</h1>
<form class="new-post" method="post">
{{ 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 %}
{% for err in errors.content %}