From 87457c0ed1d2883e150ac18fe252c7a130527947 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Sat, 10 Apr 2021 16:30:50 +0900 Subject: [PATCH 1/3] Define Post::slug() --- plume-models/src/posts.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plume-models/src/posts.rs b/plume-models/src/posts.rs index 1048fb12d..8a6e2f911 100644 --- a/plume-models/src/posts.rs +++ b/plume-models/src/posts.rs @@ -253,6 +253,11 @@ impl Post { ap_url(&format!("{}/~/{}/{}/", CONFIG.base_url, blog.fqn, slug)) } + // It's better to calc slug in insert and update + pub fn slug(title: &str) -> &str { + title + } + pub fn get_authors(&self, conn: &Connection) -> Result> { use crate::schema::post_authors; use crate::schema::users; From 6345a574987aa2512b80b8a3554be97bb00ba3e4 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Sat, 10 Apr 2021 16:32:58 +0900 Subject: [PATCH 2/3] Don't modify article title for slug --- plume-models/src/posts.rs | 9 ++++----- src/api/posts.rs | 3 +-- src/routes/posts.rs | 7 +++---- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/plume-models/src/posts.rs b/plume-models/src/posts.rs index 8a6e2f911..a66d47e29 100644 --- a/plume-models/src/posts.rs +++ b/plume-models/src/posts.rs @@ -11,7 +11,6 @@ use activitypub::{ }; use chrono::{NaiveDateTime, TimeZone, Utc}; use diesel::{self, BelongingToDsl, ExpressionMethods, QueryDsl, RunQueryDsl, SaveChangesDsl}; -use heck::KebabCase; use once_cell::sync::Lazy; use plume_common::{ activity_pub::{ @@ -653,12 +652,12 @@ impl FromId for Post { .and_then(|mut post| { let mut updated = false; - let slug = title.to_kebab_case(); + let slug = Self::slug(&title); let content = SafeString::new(&article.object_props.content_string()?); let subtitle = article.object_props.summary_string()?; let source = article.ap_object_props.source_object::()?.content; if post.slug != slug { - post.slug = slug; + post.slug = slug.to_string(); updated = true; } if post.title != title { @@ -697,7 +696,7 @@ impl FromId for Post { conn, NewPost { blog_id: blog?.id, - slug: title.to_kebab_case(), + slug: Self::slug(&title).to_string(), title, content: SafeString::new(&article.object_props.content_string()?), published: true, @@ -842,7 +841,7 @@ impl AsObject for PostUpdate { } if let Some(title) = self.title { - post.slug = title.to_kebab_case(); + post.slug = Post::slug(&title).to_string(); post.title = title; } diff --git a/src/api/posts.rs b/src/api/posts.rs index f29d56401..63490f84b 100644 --- a/src/api/posts.rs +++ b/src/api/posts.rs @@ -1,5 +1,4 @@ use chrono::NaiveDateTime; -use heck::KebabCase; use rocket_contrib::json::Json; use crate::api::{authorization::*, Api}; @@ -109,7 +108,7 @@ pub fn create( let author = User::get(&conn, auth.0.user_id)?; - let slug = &payload.title.clone().to_kebab_case(); + let slug = Post::slug(&payload.title); let date = payload.creation_date.clone().and_then(|d| { NaiveDateTime::parse_from_str(format!("{} 00:00:00", d).as_ref(), "%Y-%m-%d %H:%M:%S").ok() }); diff --git a/src/routes/posts.rs b/src/routes/posts.rs index 7cf01a6bf..df570a1d0 100644 --- a/src/routes/posts.rs +++ b/src/routes/posts.rs @@ -1,5 +1,4 @@ use chrono::Utc; -use heck::KebabCase; use rocket::http::uri::Uri; use rocket::request::LenientForm; use rocket::response::{Flash, Redirect}; @@ -236,7 +235,7 @@ pub fn update( let intl = &rockets.intl.catalog; let new_slug = if !post.published { - form.title.to_string().to_kebab_case() + Post::slug(&form.title).to_string() } else { post.slug.clone() }; @@ -400,7 +399,7 @@ pub struct NewPostForm { } pub fn valid_slug(title: &str) -> Result<(), ValidationError> { - let slug = title.to_string().to_kebab_case(); + let slug = Post::slug(title); if slug.is_empty() { Err(ValidationError::new("empty_slug")) } else if slug == "new" { @@ -419,7 +418,7 @@ pub fn create( rockets: PlumeRocket, ) -> Result { let blog = Blog::find_by_fqn(&conn, &blog_name).expect("post::create: blog error"); - let slug = form.title.to_string().to_kebab_case(); + let slug = Post::slug(&form.title); let user = rockets.user.clone().unwrap(); let mut errors = match form.validate() { From dfcdcc183369970ce13dcffac796d32a1a7a2c38 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Sat, 10 Apr 2021 16:39:23 +0900 Subject: [PATCH 3/3] Remove heck from plume and plume-models --- Cargo.lock | 2 -- Cargo.toml | 1 - plume-models/Cargo.toml | 1 - 3 files changed, 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 73673cf08..63f295b08 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2928,7 +2928,6 @@ dependencies = [ "gettext-macros", "gettext-utils", "guid-create", - "heck", "lettre", "lettre_email", "multipart", @@ -3041,7 +3040,6 @@ dependencies = [ "diesel_migrations", "glob", "guid-create", - "heck", "itertools 0.8.2", "lazy_static", "ldap3", diff --git a/Cargo.toml b/Cargo.toml index 85cebb035..a225f8888 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,6 @@ gettext = { git = "https://github.com/Plume-org/gettext/", rev = "294c54d74c699f gettext-macros = { git = "https://github.com/Plume-org/gettext-macros/", rev = "a7c605f7edd6bfbfbfe7778026bfefd88d82db10" } gettext-utils = { git = "https://github.com/Plume-org/gettext-macros/", rev = "a7c605f7edd6bfbfbfe7778026bfefd88d82db10" } guid-create = "0.1" -heck = "0.3.0" lettre = "0.9.2" lettre_email = "0.9.2" num_cpus = "1.10" diff --git a/plume-models/Cargo.toml b/plume-models/Cargo.toml index ec97f2781..6ce2100f7 100644 --- a/plume-models/Cargo.toml +++ b/plume-models/Cargo.toml @@ -10,7 +10,6 @@ ammonia = "2.1.1" askama_escape = "0.1" bcrypt = "0.5" guid-create = "0.1" -heck = "0.3.0" itertools = "0.8.0" lazy_static = "1.0" ldap3 = "0.7.1"