Extract Post::ap_url()
This commit is contained in:
parent
a419ef5319
commit
7b2bab0f9d
@ -73,12 +73,7 @@ impl Post {
|
||||
.execute(conn)?;
|
||||
let mut post = Self::last(conn)?;
|
||||
if post.ap_url.is_empty() {
|
||||
post.ap_url = ap_url(&format!(
|
||||
"{}/~/{}/{}/",
|
||||
CONFIG.base_url,
|
||||
post.get_blog(conn)?.fqn,
|
||||
post.slug
|
||||
));
|
||||
post.ap_url = Self::ap_url(post.get_blog(conn)?, &post.slug);
|
||||
let _: Post = post.save_changes(conn)?;
|
||||
}
|
||||
|
||||
@ -254,6 +249,10 @@ impl Post {
|
||||
.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>> {
|
||||
use crate::schema::post_authors;
|
||||
use crate::schema::users;
|
||||
|
@ -290,13 +290,7 @@ pub fn update(
|
||||
let newly_published = if !post.published && !form.draft {
|
||||
post.published = true;
|
||||
post.creation_date = Utc::now().naive_utc();
|
||||
// TODO: share code with Post::insert()
|
||||
post.ap_url = plume_models::ap_url(&format!(
|
||||
"{}/~/{}/{}/",
|
||||
CONFIG.base_url,
|
||||
post.get_blog(&conn).unwrap().fqn,
|
||||
new_slug
|
||||
));
|
||||
post.ap_url = Post::ap_url(post.get_blog(&conn).unwrap(), &new_slug);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
|
Loading…
Reference in New Issue
Block a user