mirror of
https://git.sr.ht/~adnano/kiln
synced 2024-11-24 03:01:11 +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 (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -46,6 +47,8 @@ type Page struct {
|
||||||
Content string
|
Content string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var titleRE = regexp.MustCompile("^# ?([^#\r\n]+)")
|
||||||
|
|
||||||
func NewPage(path string, content string) *Page {
|
func NewPage(path string, content string) *Page {
|
||||||
page := &Page{
|
page := &Page{
|
||||||
Path: path,
|
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
|
return page
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue