From 4e6d7b70cf684cfab067b6909c643b41c261ad19 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Sun, 22 Nov 2020 22:24:43 +0900 Subject: [PATCH] Keep tags as-is --- plume-common/src/utils.rs | 2 +- plume-models/src/posts.rs | 4 +--- src/api/posts.rs | 4 ++-- src/routes/posts.rs | 15 ++++++++------- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/plume-common/src/utils.rs b/plume-common/src/utils.rs index 7759a25e..e673adfc 100644 --- a/plume-common/src/utils.rs +++ b/plume-common/src/utils.rs @@ -294,7 +294,7 @@ pub fn md_to_html<'a>( } let hashtag = text_acc; let link = Tag::Link( - format!("{}tag/{}", base_url, &hashtag.to_camel_case()) + format!("{}tag/{}", base_url, &hashtag) .into(), hashtag.to_owned().into(), ); diff --git a/plume-models/src/posts.rs b/plume-models/src/posts.rs index 73c0c915..014b4aca 100644 --- a/plume-models/src/posts.rs +++ b/plume-models/src/posts.rs @@ -11,7 +11,7 @@ use activitypub::{ }; use chrono::{NaiveDateTime, TimeZone, Utc}; use diesel::{self, BelongingToDsl, ExpressionMethods, QueryDsl, RunQueryDsl, SaveChangesDsl}; -use heck::{CamelCase, KebabCase}; +use heck::KebabCase; use plume_common::{ activity_pub::{ inbox::{AsObject, FromId}, @@ -622,7 +622,6 @@ impl FromId for Post { let mut hashtags = md_to_html(&post.source, None, false, None) .2 .into_iter() - .map(|s| s.to_camel_case()) .collect::>(); if let Some(serde_json::Value::Array(tags)) = article.object_props.tag { for tag in tags { @@ -762,7 +761,6 @@ impl AsObject for PostUpdate { let mut txt_hashtags = md_to_html(&post.source, None, false, None) .2 .into_iter() - .map(|s| s.to_camel_case()) .collect::>(); if let Some(serde_json::Value::Array(mention_tags)) = self.tags { let mut mentions = vec![]; diff --git a/src/api/posts.rs b/src/api/posts.rs index a290e31a..0bce85e3 100644 --- a/src/api/posts.rs +++ b/src/api/posts.rs @@ -1,5 +1,5 @@ use chrono::NaiveDateTime; -use heck::{CamelCase, KebabCase}; +use heck::KebabCase; use rocket_contrib::json::Json; use crate::api::{authorization::*, Api}; @@ -181,7 +181,7 @@ pub fn create( Tag::insert( conn, NewTag { - tag: hashtag.to_camel_case(), + tag: hashtag, is_hashtag: true, post_id: post.id, }, diff --git a/src/routes/posts.rs b/src/routes/posts.rs index e6b10be8..3e5d6004 100644 --- a/src/routes/posts.rs +++ b/src/routes/posts.rs @@ -1,5 +1,5 @@ use chrono::Utc; -use heck::{CamelCase, KebabCase}; +use heck::KebabCase; use rocket::request::LenientForm; use rocket::response::{Flash, Redirect}; use rocket_i18n::I18n; @@ -314,18 +314,19 @@ pub fn update( let tags = form .tags .split(',') - .map(|t| t.trim().to_camel_case()) + .map(|t| t.trim()) .filter(|t| !t.is_empty()) .collect::>() .into_iter() - .filter_map(|t| Tag::build_activity(t).ok()) + .filter_map(|t| { + Tag::build_activity(t.to_string()).ok() + }) .collect::>(); post.update_tags(&conn, tags) .expect("post::update: tags error"); let hashtags = hashtags .into_iter() - .map(|h| h.to_camel_case()) .collect::>() .into_iter() .filter_map(|t| Tag::build_activity(t).ok()) @@ -489,14 +490,14 @@ pub fn create( let tags = form .tags .split(',') - .map(|t| t.trim().to_camel_case()) + .map(|t| t.trim()) .filter(|t| !t.is_empty()) .collect::>(); for tag in tags { Tag::insert( &*conn, NewTag { - tag, + tag: tag.to_string(), is_hashtag: false, post_id: post.id, }, @@ -507,7 +508,7 @@ pub fn create( Tag::insert( &*conn, NewTag { - tag: hashtag.to_camel_case(), + tag: hashtag, is_hashtag: true, post_id: post.id, },