Merge pull request 'Extract Post::ap_url()' (#918) from ap_url into main

Reviewed-on: https://git.joinplu.me/Plume/Plume/pulls/918
This commit is contained in:
KitaitiMakoto 2021-04-09 08:41:04 +00:00
commit 033fde38fe
2 changed files with 6 additions and 13 deletions

View file

@ -73,12 +73,7 @@ impl Post {
.execute(conn)?; .execute(conn)?;
let mut post = Self::last(conn)?; let mut post = Self::last(conn)?;
if post.ap_url.is_empty() { if post.ap_url.is_empty() {
post.ap_url = ap_url(&format!( post.ap_url = Self::ap_url(post.get_blog(conn)?, &post.slug);
"{}/~/{}/{}/",
CONFIG.base_url,
post.get_blog(conn)?.fqn,
post.slug
));
let _: Post = post.save_changes(conn)?; let _: Post = post.save_changes(conn)?;
} }
@ -254,6 +249,10 @@ impl Post {
.map_err(Error::from) .map_err(Error::from)
} }
pub fn ap_url(blog: Blog, slug: &str) -> String {
ap_url(&format!("{}/~/{}/{}/", CONFIG.base_url, blog.fqn, slug))
}
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;

View file

@ -290,13 +290,7 @@ pub fn update(
let newly_published = if !post.published && !form.draft { let newly_published = if !post.published && !form.draft {
post.published = true; post.published = true;
post.creation_date = Utc::now().naive_utc(); post.creation_date = Utc::now().naive_utc();
// TODO: share code with Post::insert() post.ap_url = Post::ap_url(post.get_blog(&conn).unwrap(), &new_slug);
post.ap_url = plume_models::ap_url(&format!(
"{}/~/{}/{}/",
CONFIG.base_url,
post.get_blog(&conn).unwrap().fqn,
new_slug
));
true true
} else { } else {
false false