diff qwb.go @ 4:ce2b6dde4c10

remove nesting restriction + per-page header
author Atarwn Gard <a@qwa.su>
date Sat, 14 Mar 2026 14:01:51 +0500
parents 3222f88c0afe
children 125e599b1217
line wrap: on
line diff
--- a/qwb.go	Sat Mar 14 12:05:05 2026 +0500
+++ b/qwb.go	Sat Mar 14 14:01:51 2026 +0500
@@ -196,9 +196,6 @@
 		if s.index != "" {
 			total++
 		}
-		if total < 2 {
-			break
-		}
 		b.WriteString("<ul>\n")
 		if s.index != "" {
 			navlink(&b, page{"Index", s.index}, cur)
@@ -224,6 +221,25 @@
 	return false
 }
 
+func extracth1(html string) (title, rest string) {
+	start := strings.Index(html, "<h1")
+	if start == -1 {
+		return "", html
+	}
+	close := strings.Index(html[start:], ">")
+	if close == -1 {
+		return "", html
+	}
+	content := start + close + 1
+	end := strings.Index(html[content:], "</h1>")
+	if end == -1 {
+		return "", html
+	}
+	title = html[content : content+end]
+	rest = html[:start] + html[content+end+len("</h1>"):]
+	return
+}
+
 func mdtohtml(path string) (string, error) {
 	cmd := exec.Command("lowdown", "-T", "html", "--html-no-skiphtml", "--html-no-escapehtml")
 	f, err := os.Open(path)
@@ -318,13 +334,17 @@
 			return err
 		}
 		body = fixlinks(body)
+		pageTitle, body := extracth1(body)
+		if pageTitle == "" {
+			pageTitle = cfg.headertext
+		}
 		cur := "/" + strings.TrimSuffix(rel, ".md") + ".html"
 		title := cfg.headertext
 		if filepath.Base(path) != "index.md" {
-			title = cfg.headertext + " | " + titlefromname(filepath.Base(path))
+			title = cfg.headertext + " | " + pageTitle
 		}
-		pg:= strings.ReplaceAll(tmpl, "{{TITLE}}", title)
-		pg = strings.ReplaceAll(pg, "{{SITE_TITLE}}", cfg.headertext)
+		pg := strings.ReplaceAll(tmpl, "{{TITLE}}", title)
+		pg = strings.ReplaceAll(pg, "{{SITE_TITLE}}", pageTitle)
 		pg = strings.ReplaceAll(pg, "{{FOOTER_TEXT}}", cfg.footertext)
 		pg = strings.ReplaceAll(pg, "{{CSS}}", cfg.cssfile)
 		pg = strings.ReplaceAll(pg, "{{NAV}}", buildnav(rootsec, subs, cur))