fix: remove duplicate chapter title h1, drop nav arrow, enlarge hamburger
This commit is contained in:
@@ -1896,7 +1896,7 @@ const chapterTmpl = `
|
|||||||
hx-swap="innerHTML"
|
hx-swap="innerHTML"
|
||||||
title="Back to chapter list"
|
title="Back to chapter list"
|
||||||
aria-label="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>
|
</a>
|
||||||
|
|
||||||
@@ -1909,7 +1909,6 @@ const chapterTmpl = `
|
|||||||
title="Jump to chapter"
|
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">
|
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="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">▼</span>
|
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@@ -2801,8 +2800,12 @@ func (s *Server) handleChapter(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
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
|
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)
|
http.Error(w, "markdown render error: "+err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -2898,6 +2901,28 @@ func adjacentChapters(chapters []writer.ChapterInfo, n int) (prev, next int) {
|
|||||||
return
|
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
|
// firstHeading returns the text of the first non-empty line, stripping a
|
||||||
// leading "# " markdown heading marker. Falls back to fallback.
|
// leading "# " markdown heading marker. Falls back to fallback.
|
||||||
func firstHeading(md, fallback string) string {
|
func firstHeading(md, fallback string) string {
|
||||||
|
|||||||
BIN
scraper/scraper
Executable file
BIN
scraper/scraper
Executable file
Binary file not shown.
Reference in New Issue
Block a user