Merge pull request 'Fix #326 and #721: Keep title in URI' (#920) from keep-title-in-uri into main

Reviewed-on: https://git.joinplu.me/Plume/Plume/pulls/920
This commit is contained in:
KitaitiMakoto 2021-04-10 08:27:31 +00:00
commit fa7a44f6bb
6 changed files with 13 additions and 15 deletions

2
Cargo.lock generated
View File

@ -2928,7 +2928,6 @@ dependencies = [
"gettext-macros", "gettext-macros",
"gettext-utils", "gettext-utils",
"guid-create", "guid-create",
"heck",
"lettre", "lettre",
"lettre_email", "lettre_email",
"multipart", "multipart",
@ -3041,7 +3040,6 @@ dependencies = [
"diesel_migrations", "diesel_migrations",
"glob", "glob",
"guid-create", "guid-create",
"heck",
"itertools 0.8.2", "itertools 0.8.2",
"lazy_static", "lazy_static",
"ldap3", "ldap3",

View File

@ -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-macros = { git = "https://github.com/Plume-org/gettext-macros/", rev = "a7c605f7edd6bfbfbfe7778026bfefd88d82db10" }
gettext-utils = { 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" guid-create = "0.1"
heck = "0.3.0"
lettre = "0.9.2" lettre = "0.9.2"
lettre_email = "0.9.2" lettre_email = "0.9.2"
num_cpus = "1.10" num_cpus = "1.10"

View File

@ -10,7 +10,6 @@ ammonia = "2.1.1"
askama_escape = "0.1" askama_escape = "0.1"
bcrypt = "0.5" bcrypt = "0.5"
guid-create = "0.1" guid-create = "0.1"
heck = "0.3.0"
itertools = "0.8.0" itertools = "0.8.0"
lazy_static = "1.0" lazy_static = "1.0"
ldap3 = "0.7.1" ldap3 = "0.7.1"

View File

@ -11,7 +11,6 @@ use activitypub::{
}; };
use chrono::{NaiveDateTime, TimeZone, Utc}; use chrono::{NaiveDateTime, TimeZone, Utc};
use diesel::{self, BelongingToDsl, ExpressionMethods, QueryDsl, RunQueryDsl, SaveChangesDsl}; use diesel::{self, BelongingToDsl, ExpressionMethods, QueryDsl, RunQueryDsl, SaveChangesDsl};
use heck::KebabCase;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use plume_common::{ use plume_common::{
activity_pub::{ activity_pub::{
@ -253,6 +252,11 @@ impl Post {
ap_url(&format!("{}/~/{}/{}/", CONFIG.base_url, blog.fqn, slug)) 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<Vec<User>> { pub fn get_authors(&self, conn: &Connection) -> Result<Vec<User>> {
use crate::schema::post_authors; use crate::schema::post_authors;
use crate::schema::users; use crate::schema::users;
@ -648,12 +652,12 @@ impl FromId<DbConn> for Post {
.and_then(|mut post| { .and_then(|mut post| {
let mut updated = false; 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 content = SafeString::new(&article.object_props.content_string()?);
let subtitle = article.object_props.summary_string()?; let subtitle = article.object_props.summary_string()?;
let source = article.ap_object_props.source_object::<Source>()?.content; let source = article.ap_object_props.source_object::<Source>()?.content;
if post.slug != slug { if post.slug != slug {
post.slug = slug; post.slug = slug.to_string();
updated = true; updated = true;
} }
if post.title != title { if post.title != title {
@ -692,7 +696,7 @@ impl FromId<DbConn> for Post {
conn, conn,
NewPost { NewPost {
blog_id: blog?.id, blog_id: blog?.id,
slug: title.to_kebab_case(), slug: Self::slug(&title).to_string(),
title, title,
content: SafeString::new(&article.object_props.content_string()?), content: SafeString::new(&article.object_props.content_string()?),
published: true, published: true,
@ -837,7 +841,7 @@ impl AsObject<User, Update, &DbConn> for PostUpdate {
} }
if let Some(title) = self.title { if let Some(title) = self.title {
post.slug = title.to_kebab_case(); post.slug = Post::slug(&title).to_string();
post.title = title; post.title = title;
} }

View File

@ -1,5 +1,4 @@
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use heck::KebabCase;
use rocket_contrib::json::Json; use rocket_contrib::json::Json;
use crate::api::{authorization::*, Api}; use crate::api::{authorization::*, Api};
@ -109,7 +108,7 @@ pub fn create(
let author = User::get(&conn, auth.0.user_id)?; 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| { 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() NaiveDateTime::parse_from_str(format!("{} 00:00:00", d).as_ref(), "%Y-%m-%d %H:%M:%S").ok()
}); });

View File

@ -1,5 +1,4 @@
use chrono::Utc; use chrono::Utc;
use heck::KebabCase;
use rocket::http::uri::Uri; use rocket::http::uri::Uri;
use rocket::request::LenientForm; use rocket::request::LenientForm;
use rocket::response::{Flash, Redirect}; use rocket::response::{Flash, Redirect};
@ -236,7 +235,7 @@ pub fn update(
let intl = &rockets.intl.catalog; let intl = &rockets.intl.catalog;
let new_slug = if !post.published { let new_slug = if !post.published {
form.title.to_string().to_kebab_case() Post::slug(&form.title).to_string()
} else { } else {
post.slug.clone() post.slug.clone()
}; };
@ -400,7 +399,7 @@ pub struct NewPostForm {
} }
pub fn valid_slug(title: &str) -> Result<(), ValidationError> { 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() { if slug.is_empty() {
Err(ValidationError::new("empty_slug")) Err(ValidationError::new("empty_slug"))
} else if slug == "new" { } else if slug == "new" {
@ -419,7 +418,7 @@ pub fn create(
rockets: PlumeRocket, rockets: PlumeRocket,
) -> Result<RespondOrRedirect, ErrorPage> { ) -> Result<RespondOrRedirect, ErrorPage> {
let blog = Blog::find_by_fqn(&conn, &blog_name).expect("post::create: blog error"); 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 user = rockets.user.clone().unwrap();
let mut errors = match form.validate() { let mut errors = match form.validate() {