From 94a386ea2cd166f9ff1539cac89154462ee31af1 Mon Sep 17 00:00:00 2001 From: Bat Date: Tue, 4 Sep 2018 12:26:13 +0100 Subject: [PATCH] Add subtitles to articles Fix #152 --- .../2018-09-04-104828_posts_add_subtitle/down.sql | 2 ++ .../2018-09-04-104828_posts_add_subtitle/up.sql | 2 ++ plume-models/src/posts.rs | 12 ++++++++---- plume-models/src/schema.rs | 1 + po/de.po | 4 ++++ po/en.po | 3 +++ po/fr.po | 8 +++++++- po/gl.po | 7 ++++++- po/nb.po | 4 ++++ po/pl.po | 4 ++++ po/plume.pot | 3 +++ src/routes/posts.rs | 4 +++- static/main.css | 7 +++++++ templates/macros.html.tera | 8 +++++++- templates/posts/details.html.tera | 1 + templates/posts/new.html.tera | 1 + 16 files changed, 63 insertions(+), 8 deletions(-) create mode 100644 migrations/2018-09-04-104828_posts_add_subtitle/down.sql create mode 100644 migrations/2018-09-04-104828_posts_add_subtitle/up.sql diff --git a/migrations/2018-09-04-104828_posts_add_subtitle/down.sql b/migrations/2018-09-04-104828_posts_add_subtitle/down.sql new file mode 100644 index 00000000..0c39127b --- /dev/null +++ b/migrations/2018-09-04-104828_posts_add_subtitle/down.sql @@ -0,0 +1,2 @@ +-- This file should undo anything in `up.sql` +ALTER TABLE posts DROP COLUMN subtitle; diff --git a/migrations/2018-09-04-104828_posts_add_subtitle/up.sql b/migrations/2018-09-04-104828_posts_add_subtitle/up.sql new file mode 100644 index 00000000..17ab4754 --- /dev/null +++ b/migrations/2018-09-04-104828_posts_add_subtitle/up.sql @@ -0,0 +1,2 @@ +-- Your SQL goes here +ALTER TABLE posts ADD COLUMN subtitle TEXT NOT NULL DEFAULT ''; diff --git a/plume-models/src/posts.rs b/plume-models/src/posts.rs index 5b67a66d..73c8c985 100644 --- a/plume-models/src/posts.rs +++ b/plume-models/src/posts.rs @@ -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, - 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::(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::(to.into_iter().map(Id::new).collect()).expect("Article::into_activity: to error"); @@ -250,7 +253,8 @@ impl FromActivity 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() { diff --git a/plume-models/src/schema.rs b/plume-models/src/schema.rs index 1671bf72..7214871e 100644 --- a/plume-models/src/schema.rs +++ b/plume-models/src/schema.rs @@ -125,6 +125,7 @@ table! { license -> Varchar, creation_date -> Timestamp, ap_url -> Varchar, + subtitle -> Text, } } diff --git a/po/de.po b/po/de.po index e177a94a..cf8bd3d9 100644 --- a/po/de.po +++ b/po/de.po @@ -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" diff --git a/po/en.po b/po/en.po index deccf96e..08d76670 100644 --- a/po/en.po +++ b/po/en.po @@ -497,3 +497,6 @@ msgstr "" msgid "" "Sorry, but registrations are closed on this instance. Try to find another one" msgstr "" + +msgid "Subtitle" +msgstr "" diff --git a/po/fr.po b/po/fr.po index e1f3d757..b9aeecd7 100644 --- a/po/fr.po +++ b/po/fr.po @@ -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" diff --git a/po/gl.po b/po/gl.po index 7f68eef0..5c1eafbb 100644 --- a/po/gl.po +++ b/po/gl.po @@ -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" diff --git a/po/nb.po b/po/nb.po index 275ac691..07257571 100644 --- a/po/nb.po +++ b/po/nb.po @@ -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" diff --git a/po/pl.po b/po/pl.po index 0b879eca..be9d2790 100644 --- a/po/pl.po +++ b/po/pl.po @@ -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" diff --git a/po/plume.pot b/po/plume.pot index ca6c8851..28d6ef68 100644 --- a/po/plume.pot +++ b/po/plume.pot @@ -486,3 +486,6 @@ msgstr "" msgid "Sorry, but registrations are closed on this instance. Try to find another one" msgstr "" + +msgid "Subtitle" +msgstr "" diff --git a/src/routes/posts.rs b/src/routes/posts.rs index 44376b89..678b2623 100644 --- a/src/routes/posts.rs +++ b/src/routes/posts.rs @@ -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, 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 { diff --git a/static/main.css b/static/main.css index 58521bd5..5aa1c0f4 100644 --- a/static/main.css +++ b/static/main.css @@ -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 == */ diff --git a/templates/macros.html.tera b/templates/macros.html.tera index defe0137..e1a7e989 100644 --- a/templates/macros.html.tera +++ b/templates/macros.html.tera @@ -2,7 +2,13 @@

{{ article.post.title }}

{{ article.post.content | safe | striptags | truncate(length=200) }}

+

+ {% if article.post.subtitle | length > 0 %} + {{ article.post.subtitle }} + {% else %} + {{ article.post.content | safe | striptags | truncate(length=200) }} + {% endif %} +

{{ "By {{ link_1 }}{{ link_2 }}{{ link_3 }}{{ name | escape }}{{ link_4 }}" | _( diff --git a/templates/posts/details.html.tera b/templates/posts/details.html.tera index e7f3dd08..39cfdca5 100644 --- a/templates/posts/details.html.tera +++ b/templates/posts/details.html.tera @@ -11,6 +11,7 @@ {% block content %}

{{ article.post.title }}

+

{{ article.post.subtitle }}

{{ 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 %}