diff options
| author | t <t@tjp.lol> | 2026-07-12 17:46:15 -0600 |
|---|---|---|
| committer | t <t@tjp.lol> | 2026-07-12 17:46:20 -0600 |
| commit | b3673ecd7865c9144b68e5bfd34318c98e398931 (patch) | |
| tree | df96a27443f8498a3137a97fa4a07ab5bd371f8f /main.go | |
| parent | 5cef3624289c11b21c661b314973bc85183bc3c6 (diff) | |
include the title h1 in `.Sections`
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 26 |
1 files changed, 16 insertions, 10 deletions
@@ -312,9 +312,7 @@ func extractTitle(doc ast.Node, source []byte) string { if !ok || heading.Level != 1 { continue } - title := strings.TrimSpace(string(heading.Text(source))) - doc.RemoveChild(doc, node) - return title + return strings.TrimSpace(string(heading.Text(source))) } return "" } @@ -427,17 +425,25 @@ func relativePath(from, target string) string { return rel } -func sortPages(pages []*Page, key string) []*Page { +func sortPages(pages []*Page, keys ...string) []*Page { result := slices.Clone(pages) - sort.SliceStable(result, func(i, j int) bool { - if key == "mod_time" { - return result[i].ModTime.After(result[j].ModTime) + date := func(page *Page) time.Time { + for _, key := range keys { + if key == "mod_time" { + return page.ModTime + } + if value, ok := asTime(page.Meta[key]); ok { + return value + } } - if key == "title" { + return time.Time{} + } + sort.SliceStable(result, func(i, j int) bool { + if len(keys) == 1 && keys[0] == "title" { return strings.ToLower(result[i].Title) < strings.ToLower(result[j].Title) } - a, _ := asTime(result[i].Meta[key]) - b, _ := asTime(result[j].Meta[key]) + a := date(result[i]) + b := date(result[j]) return a.After(b) }) return result |
