Render one chapter format, not "Ch Chapter 250"

The userscript writes last_chapter/latest_chapter as "Chapter N" and the
poller writes the same label, so the templates' own "Ch " prefix doubled it on
every real row. A manual edit through the web UI stores a bare "250", so the
list carried two formats at once and stopped being scannable.

Move the formatting out of the templates into DisplayChapter/DisplayLatest on
Bookmark, which strip a leading "Chapter"/"Ch." lead-in and re-add exactly one
"Ch ", falling back to the numeric column when the label is empty.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-30 18:53:17 +07:00
parent 9cb9b51b41
commit d16789226c
4 changed files with 78 additions and 4 deletions
+38
View File
@@ -1034,3 +1034,41 @@ func TestOpenStoreMigratesAsuraHashlessCollision(t *testing.T) {
t.Fatalf("merge kept wrong row: %+v", merged)
}
}
func TestDisplayChapter(t *testing.T) {
cases := []struct {
name string
raw string
num float64
want string
}{
{"userscript label", "Chapter 250", 250, "Ch 250"},
{"abbreviated with dot", "Ch. 12", 12, "Ch 12"},
{"lowercase abbreviation", "ch 3", 3, "Ch 3"},
{"bare number from a manual edit", "45.5", 45.5, "Ch 45.5"},
{"empty falls back to the number", "", 7, "Ch 7"},
{"empty and zero", "", 0, "Ch 0"},
{"label with no number passes through", "Prologue", 0, "Prologue"},
{"title-like label keeps its words", "Chapter of the Sun", 0, "of the Sun"},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
if got := displayChapter(tc.raw, tc.num); got != tc.want {
t.Errorf("displayChapter(%q, %v) = %q, want %q", tc.raw, tc.num, got, tc.want)
}
})
}
b := Bookmark{LastChapter: "Chapter 9", LastChapterNum: 9}
if got := b.DisplayChapter(); got != "Ch 9" {
t.Errorf("DisplayChapter() = %q, want %q", got, "Ch 9")
}
if got := b.DisplayLatest(); got != "Ch 0" {
t.Errorf("DisplayLatest() with nothing captured = %q, want %q", got, "Ch 0")
}
num := 11.0
b.LatestChapter, b.LatestChapterNum = "Chapter 11", &num
if got := b.DisplayLatest(); got != "Ch 11" {
t.Errorf("DisplayLatest() = %q, want %q", got, "Ch 11")
}
}