From 95ea2485184712f4646754fe8c8f481deef301e7 Mon Sep 17 00:00:00 2001 From: Trinity Pointard Date: Sat, 20 Oct 2018 19:27:49 +0200 Subject: [PATCH] Add support for hashtag on user interface Add migration to fix typo Add support for linking hashtags with posts Rework tag search page so it says a nicer message than page not found when no post use that tag Add new string to translation --- .../down.sql | 2 + .../2018-10-20-164036_fix_hastag_typo/up.sql | 1 + .../down.sql | 10 +++++ .../2018-10-20-164036_fix_hastag_typo/up.sql | 10 +++++ plume-common/src/utils.rs | 2 +- plume-models/src/schema.rs | 2 +- plume-models/src/tags.rs | 6 +-- po/en.po | 3 ++ po/fr.po | 3 ++ po/gl.po | 3 ++ po/nb.po | 3 ++ po/pl.po | 3 ++ po/plume.pot | 3 ++ src/routes/posts.rs | 37 +++++++++++++++---- src/routes/tags.rs | 16 ++++---- templates/tags/index.html.tera | 20 ++++++---- 16 files changed, 96 insertions(+), 28 deletions(-) create mode 100644 migrations/postgres/2018-10-20-164036_fix_hastag_typo/down.sql create mode 100644 migrations/postgres/2018-10-20-164036_fix_hastag_typo/up.sql create mode 100644 migrations/sqlite/2018-10-20-164036_fix_hastag_typo/down.sql create mode 100644 migrations/sqlite/2018-10-20-164036_fix_hastag_typo/up.sql diff --git a/migrations/postgres/2018-10-20-164036_fix_hastag_typo/down.sql b/migrations/postgres/2018-10-20-164036_fix_hastag_typo/down.sql new file mode 100644 index 00000000..e96261d7 --- /dev/null +++ b/migrations/postgres/2018-10-20-164036_fix_hastag_typo/down.sql @@ -0,0 +1,2 @@ +-- This file should undo anything in `up.sql` +ALTER TABLE tags RENAME COLUMN is_hashtag TO is_hastag; diff --git a/migrations/postgres/2018-10-20-164036_fix_hastag_typo/up.sql b/migrations/postgres/2018-10-20-164036_fix_hastag_typo/up.sql new file mode 100644 index 00000000..32914c21 --- /dev/null +++ b/migrations/postgres/2018-10-20-164036_fix_hastag_typo/up.sql @@ -0,0 +1 @@ +ALTER TABLE tags RENAME COLUMN is_hastag TO is_hashtag; diff --git a/migrations/sqlite/2018-10-20-164036_fix_hastag_typo/down.sql b/migrations/sqlite/2018-10-20-164036_fix_hastag_typo/down.sql new file mode 100644 index 00000000..47965c12 --- /dev/null +++ b/migrations/sqlite/2018-10-20-164036_fix_hastag_typo/down.sql @@ -0,0 +1,10 @@ +CREATE TABLE tags2 ( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + tag TEXT NOT NULL DEFAULT '', + is_hastag BOOLEAN NOT NULL DEFAULT 'f', + post_id INTEGER REFERENCES posts(id) ON DELETE CASCADE NOT NULL +); + +INSERT INTO tags2 SELECT * FROM tags; +DROP TABLE tags; +ALTER TABLE tags2 RENAME TO tags; diff --git a/migrations/sqlite/2018-10-20-164036_fix_hastag_typo/up.sql b/migrations/sqlite/2018-10-20-164036_fix_hastag_typo/up.sql new file mode 100644 index 00000000..5993b3c4 --- /dev/null +++ b/migrations/sqlite/2018-10-20-164036_fix_hastag_typo/up.sql @@ -0,0 +1,10 @@ +CREATE TABLE tags2 ( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + tag TEXT NOT NULL DEFAULT '', + is_hashtag BOOLEAN NOT NULL DEFAULT 'f', + post_id INTEGER REFERENCES posts(id) ON DELETE CASCADE NOT NULL +); + +INSERT INTO tags2 SELECT * FROM tags; +DROP TABLE tags; +ALTER TABLE tags2 RENAME TO tags; diff --git a/plume-common/src/utils.rs b/plume-common/src/utils.rs index 1f06b44d..36f9558a 100644 --- a/plume-common/src/utils.rs +++ b/plume-common/src/utils.rs @@ -68,7 +68,7 @@ pub fn md_to_html(md: &str) -> (String, Vec, Vec) { } else { text_acc }; - let link = Tag::Link(format!("/tag/{}", hashtag).into(), hashtag.to_string().into()); + let link = Tag::Link(format!("/tag/{}", hashtag.to_camel_case()).into(), hashtag.to_string().into()); hashtags.push(hashtag.clone()); events.push(Event::Start(link.clone())); diff --git a/plume-models/src/schema.rs b/plume-models/src/schema.rs index 7d51d678..b2a01083 100644 --- a/plume-models/src/schema.rs +++ b/plume-models/src/schema.rs @@ -144,7 +144,7 @@ table! { tags (id) { id -> Int4, tag -> Text, - is_hastag -> Bool, + is_hashtag -> Bool, post_id -> Int4, } } diff --git a/plume-models/src/tags.rs b/plume-models/src/tags.rs index c15dd14e..99e6cb6c 100644 --- a/plume-models/src/tags.rs +++ b/plume-models/src/tags.rs @@ -9,7 +9,7 @@ use schema::tags; pub struct Tag { pub id: i32, pub tag: String, - pub is_hastag: bool, + pub is_hashtag: bool, pub post_id: i32 } @@ -17,7 +17,7 @@ pub struct Tag { #[table_name = "tags"] pub struct NewTag { pub tag: String, - pub is_hastag: bool, + pub is_hashtag: bool, pub post_id: i32 } @@ -40,7 +40,7 @@ impl Tag { pub fn from_activity(conn: &Connection, tag: Hashtag, post: i32) -> Tag { Tag::insert(conn, NewTag { tag: tag.name_string().expect("Tag::from_activity: name error"), - is_hastag: false, + is_hashtag: false, post_id: post }) } diff --git a/po/en.po b/po/en.po index 7586ad98..646250b5 100644 --- a/po/en.po +++ b/po/en.po @@ -608,3 +608,6 @@ msgstr "" msgid "This post isn't published yet." msgstr "" + +msgid "There is currently no article with that tag" +msgstr "" diff --git a/po/fr.po b/po/fr.po index c858f2d5..8e1a5b46 100644 --- a/po/fr.po +++ b/po/fr.po @@ -624,3 +624,6 @@ msgstr "Utilisateurs" msgid "This post isn't published yet." msgstr "Cet article n’est pas encore publié." + +msgid "There is currently no article with that tag" +msgstr "Il n'y a pas encore d'article avec ce tag" diff --git a/po/gl.po b/po/gl.po index fd219f78..a9782da8 100644 --- a/po/gl.po +++ b/po/gl.po @@ -611,3 +611,6 @@ msgstr "Usuarias" #, fuzzy msgid "This post isn't published yet." msgstr "Esto é un borrador, non publicar por agora." + +msgid "There is currently no article with that tag" +msgstr "" diff --git a/po/nb.po b/po/nb.po index b6369909..136f23d5 100644 --- a/po/nb.po +++ b/po/nb.po @@ -633,6 +633,9 @@ msgstr "Brukernavn" msgid "This post isn't published yet." msgstr "" +msgid "There is currently no article with that tag" +msgstr "" + #~ msgid "One reshare" #~ msgid_plural "{{ count }} reshares" #~ msgstr[0] "Én deling" diff --git a/po/pl.po b/po/pl.po index 9e28d738..839fe528 100644 --- a/po/pl.po +++ b/po/pl.po @@ -623,6 +623,9 @@ msgstr "Użytkownicy" msgid "This post isn't published yet." msgstr "Ten wpis nie został jeszcze opublikowany." +msgid "There is currently no article with that tag" +msgstr "" + #~ msgid "One reshare" #~ msgid_plural "{{ count }} reshares" #~ msgstr[0] "Jedno udostępnienie" diff --git a/po/plume.pot b/po/plume.pot index 423338ed..99ee663a 100644 --- a/po/plume.pot +++ b/po/plume.pot @@ -591,3 +591,6 @@ msgstr "" msgid "This post isn't published yet." msgstr "" + +msgid "There is currently no article with that tag" +msgstr "" diff --git a/src/routes/posts.rs b/src/routes/posts.rs index 518c83a1..b7692f5e 100644 --- a/src/routes/posts.rs +++ b/src/routes/posts.rs @@ -139,7 +139,7 @@ fn edit(blog: String, slug: String, user: User, conn: DbConn) -> Option