diff --git a/main.go b/main.go index 24b6fa9..1a3410d 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "log" "path/filepath" + "regexp" "time" ) @@ -46,6 +47,8 @@ type Page struct { Content string } +var titleRE = regexp.MustCompile("^# ?([^#\r\n]+)") + func NewPage(path string, content string) *Page { page := &Page{ Path: path, @@ -63,6 +66,11 @@ func NewPage(path string, content string) *Page { } } + // Try to parse the title from the contents + if submatches := titleRE.FindStringSubmatch(content); submatches != nil { + page.Title = submatches[1] + } + return page }