use 'note' as slug for untitled posts

This commit is contained in:
Niko Abeler 2022-11-19 16:08:48 +01:00
parent 396b84c9bb
commit 0934aaa121
1 changed files with 7 additions and 3 deletions

10
user.go
View File

@ -209,7 +209,11 @@ func (user User) GetPost(id string) (*Post, error) {
}
func (user User) CreateNewPostFull(meta PostMeta, content string) (*Post, error) {
folder_name := toDirectoryName(meta.Title)
slugHint := meta.Title
if slugHint == "" {
slugHint = "note"
}
folder_name := toDirectoryName(slugHint)
post_dir := path.Join(user.Dir(), "public", folder_name)
// if post already exists, add -n to the end of the name
@ -217,13 +221,13 @@ func (user User) CreateNewPostFull(meta PostMeta, content string) (*Post, error)
for {
if dirExists(post_dir) {
i++
folder_name = toDirectoryName(fmt.Sprintf("%s-%d", meta.Title, i))
folder_name = toDirectoryName(fmt.Sprintf("%s-%d", slugHint, i))
post_dir = path.Join(user.Dir(), "public", folder_name)
} else {
break
}
}
post := Post{user: &user, id: folder_name, title: meta.Title}
post := Post{user: &user, id: folder_name, title: slugHint}
initial_content := ""
initial_content += "---\n"