Repository navigation
fix: an intro no longer shifts embedded "Chapter N" chapter names in a merged book - #531
Merged
Merged
Conversation
…a merged book (#509) A merged book whose files are tagged "Intro", "Chapter 1", "Chapter 2" and whose file names hold no titles now keeps those names. Every "Chapter N" tag used to count as generic and was replaced by the file's position, so the intro pushed each chapter up by one. The numbered tags are kept only when every title in the set is distinct (case and spacing folded, "Chapter 01" = "Chapter 1"), the fallback names of untagged files included. Per-disc sets whose tags restart at "Chapter 1", or an untagged intro beside "Chapter 1..N", keep numbering by position as before. One log line says which way the set went. Based on #525 by @mvanhorn. Co-authored-by: mvanhorn <455140+mvanhorn@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A merged book whose files are tagged
Intro & Dedication,Chapter 1,Chapter 2and whose file names hold no titles now keeps those chapter names. Before, every embeddedChapter Ntag counted as generic and was replaced by the file's position, so the intro pushed each chapter up by one (Chapter 1becameChapter 2). The numbered tags are kept only when the whole book's titles stay distinct, so per-disc sets whose tags restart atChapter 1keepChapter 1..Nnumbering exactly as before.Changes
src/lib/utils/chapter-merger.tsgetChapterTitletakes akeepNumberedflag: with it, an embeddedChapter Ntag (any case, zero padding) is used as the file's title. File-name titles still come first, a tag that is the book title is still skipped, andTrack N, bare numbers andPart Nstill fall back to position numbering.analyzeChapterFiles, after ordering, works out the titles both ways. It keeps the numbered tags only if every title in the set is distinct, compared case- and space-folded with the number parsed (Chapter 01=Chapter 1), counting the fallback names of untagged files. Any repeat gives the whole set position numbering, the same names as onmain.Chapter titles: keeping N embedded "Chapter N" title(s) (every title in the set is distinct)orChapter titles: "<title>" repeats across the set - dropping embedded "Chapter N" titles, numbering chapters by position.documentation/features/chapter-merging.md: the rule, the repeated-tags fallback, the log line, and a Fixed Issues entry for Bug: Chapter merging renumbers valid embedded chapter titles after an introduction #509.documentation/TABLEOFCONTENTS.md: pointer to it.Tests
tests/utils/chapter-merger.titles.test.ts(new): the reported case (intro plusChapter 1..4tags, no titles in file names) keeps the tags and logs the keep line; per-discChapter 1, 2, 1, 2tags giveChapter 1..4with the multi-disc order (and log the drop line) and without it; an untagged intro besideChapter 1..3givesChapter 1..4with no repeats;chapter 01counts as a repeat ofChapter 1; file-name titles andTrack/bare/Parttags beside numbered tags; no log line when no file has a numbered tag.tests/utils/chapter-merger.test.ts: the intro case throughmergeChaptersforChapter 1/Chapter 2andChapter 01/CHAPTER 10, asserting the FFMETADATA chapter titles, in both orders; the book-title fallback also runs with every file taggedChapter 10.tests/utils/chapter-merger.order.test.tsunchanged and passing.main(d2f81afsrcwith this branch's tests): 5 tests (the reported case, the mixed case, both merge cases, and the per-disc multi-disc case on its log line). The per-disc, untagged-intro and padding cases pass onmainby design: they guard against duplicate names, and fail against a per-file-only version of the fix (5 of 7 in the new file).Checks
vitest relatedonchapter-merger.tsplus the test files: PASS, 120 files, 1554 passed, 1 skippedtsc --noEmit: cleanmain, unusedCHAPTER_PATTERNS)Risk and rollback
Chapter Ntags whose titles are all distinct. Those names now keep the tag's own case and padding (Chapter 01). Ordering and timing are unchanged. Already merged books are not touched.Chapter 3, 1, 2on files played in that order), or when the chosen order is file-name order (track tags have gaps). The names then match what the files say.Closes #509
Based on #525 by @mvanhorn, with a check across the whole book so per-disc sets keep their numbering.
Release note
🤖 Generated with Claude Code