Merge pull request #436 from writeas/publish-with-slug

Support `slug` parameter when publishing a post
This commit is contained in:
Matt Baer 2021-03-09 09:59:57 -05:00 committed by GitHub
commit 321c1af607
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -638,6 +638,9 @@ func (db *datastore) CreatePost(userID, collID int64, post *SubmittedPost) (*Pos
ownerCollID.Int64 = collID ownerCollID.Int64 = collID
ownerCollID.Valid = true ownerCollID.Valid = true
var slugVal string var slugVal string
if post.Slug != nil && *post.Slug != "" {
slugVal = *post.Slug
} else {
if post.Title != nil && *post.Title != "" { if post.Title != nil && *post.Title != "" {
slugVal = getSlug(*post.Title, post.Language.String) slugVal = getSlug(*post.Title, post.Language.String)
if slugVal == "" { if slugVal == "" {
@ -646,6 +649,7 @@ func (db *datastore) CreatePost(userID, collID int64, post *SubmittedPost) (*Pos
} else { } else {
slugVal = getSlug(*post.Content, post.Language.String) slugVal = getSlug(*post.Content, post.Language.String)
} }
}
if slugVal == "" { if slugVal == "" {
slugVal = friendlyID slugVal = friendlyID
} }