Don't modify article title for slug

This commit is contained in:
Kitaiti Makoto
2021-04-10 16:32:58 +09:00
parent 87457c0ed1
commit 6345a57498
3 changed files with 8 additions and 11 deletions
+1 -2
View File
@@ -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()
});
+3 -4
View File
@@ -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<RespondOrRedirect, ErrorPage> {
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() {