From e45dd6c7c87bf87256c6d49813f13519194e2a9c Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Sat, 25 Feb 2023 13:00:05 -0800 Subject: [PATCH] default title --- walk.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/walk.go b/walk.go index 769208a..59e4dcb 100644 --- a/walk.go +++ b/walk.go @@ -60,10 +60,17 @@ func walk(root, ext string, index bool, ignorePaths map[string]struct{}) (res [] info, _ := os.Stat(s) source := processSource(trim(s, root, ".md")) + // default title + title := matter.Title + if title == "" { + fileName := d.Name() + title = strings.TrimSuffix(filepath.Base(fileName), filepath.Ext(fileName)) + } + // add to content and link index i[source] = Content{ LastModified: info.ModTime(), - Title: matter.Title, + Title: title, Content: body, } res = append(res, parse(s, root)...)