mirror of
https://git.sr.ht/~adnano/kiln
synced 2024-12-28 14:40:16 +00:00
Parse titles from pages
This commit is contained in:
parent
40ae714d6d
commit
81bf4f8e9b
8
main.go
8
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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue