fix: remove duplicate chapter title h1, drop nav arrow, enlarge hamburger
Some checks failed
CI / Lint (push) Has been cancelled
CI / Test (push) Has been cancelled
CI / Build (push) Has been cancelled

This commit is contained in:
Admin
2026-03-02 11:15:21 +05:00
parent 0503f69537
commit 7ed5eb0d69
2 changed files with 28 additions and 3 deletions

View File

@@ -1896,7 +1896,7 @@ const chapterTmpl = `
hx-swap="innerHTML"
title="Back to chapter list"
aria-label="Back to chapter list"
class="flex-shrink-0 px-2 py-1.5 rounded-lg text-zinc-400 hover:text-amber-400 transition-colors text-base leading-none no-underline">
class="flex-shrink-0 px-2 py-1.5 rounded-lg text-zinc-400 hover:text-amber-400 transition-colors text-xl leading-none no-underline">
☰
</a>
@@ -1909,7 +1909,6 @@ const chapterTmpl = `
title="Jump to chapter"
class="flex-1 min-w-0 flex items-center justify-center gap-1.5 overflow-hidden bg-transparent border-none cursor-pointer py-1 px-1">
<span class="overflow-hidden text-ellipsis whitespace-nowrap text-[0.8125rem] text-zinc-400 max-w-full">{{.Title}}</span>
<span class="flex-shrink-0 text-[0.625rem] text-zinc-600" aria-hidden="true">&#9660;</span>
</button>
</div>
@@ -2801,8 +2800,12 @@ func (s *Server) handleChapter(w http.ResponseWriter, r *http.Request) {
return
}
// Strip the first heading line so it isn't rendered as a duplicate <h1>
// inside the article (the template already renders an explicit <h1>).
rawForHTML := stripFirstHeadingLine(raw)
var htmlBuf bytes.Buffer
if err := md.Convert([]byte(raw), &htmlBuf); err != nil {
if err := md.Convert([]byte(rawForHTML), &htmlBuf); err != nil {
http.Error(w, "markdown render error: "+err.Error(), http.StatusInternalServerError)
return
}
@@ -2898,6 +2901,28 @@ func adjacentChapters(chapters []writer.ChapterInfo, n int) (prev, next int) {
return
}
// stripFirstHeadingLine removes the first non-empty line if it is a markdown
// heading (starts with one or more "#"). This prevents the heading from being
// rendered as a duplicate <h1> inside the article when the template already
// renders an explicit title above the article.
func stripFirstHeadingLine(src string) string {
lines := strings.SplitN(src, "\n", -1)
for i, line := range lines {
trimmed := strings.TrimSpace(line)
if trimmed == "" {
continue
}
if strings.HasPrefix(trimmed, "#") {
// Remove this line and return the rest.
rest := strings.Join(append(lines[:i], lines[i+1:]...), "\n")
return strings.TrimLeft(rest, "\n")
}
// First non-empty line is not a heading — nothing to strip.
break
}
return src
}
// firstHeading returns the text of the first non-empty line, stripping a
// leading "# " markdown heading marker. Falls back to fallback.
func firstHeading(md, fallback string) string {