From 0934aaa12135b1c6ffba9c1a2ee42ef926ca9112 Mon Sep 17 00:00:00 2001 From: Niko Abeler Date: Sat, 19 Nov 2022 16:08:48 +0100 Subject: [PATCH] use 'note' as slug for untitled posts --- user.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/user.go b/user.go index a909846..874743a 100644 --- a/user.go +++ b/user.go @@ -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"