fix(cbz): compare page paths segment by segment for reading order - #79
Merged
Conversation
Sorting flattened archive paths as plain strings puts "Chapter 0060 (2)/001.jpg" before "Chapter 0060/001.jpg" because a space sorts before a slash, so part 2 of a split chapter renders ahead of part 1. Compare paths per segment with a numeric collator instead, with the shorter path winning at divergence, so a folder that is a prefix of a sibling sorts first. Numeric collation also keeps unpadded pages such as 2.jpg ahead of 10.jpg. Fixes readest/readest#5745 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
chrox
added a commit
to readest/readest
that referenced
this pull request
Aug 17, 2026
…js#79 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
chrox
added a commit
to readest/readest
that referenced
this pull request
Aug 17, 2026
* fix(cbz): order split chapter folders base-first (#5745) A CBZ chapter split across folders sharing a chapter number, such as Chapter 0060/ and Chapter 0060 (2)/, rendered part 2 before part 1: image paths were flattened and sorted as plain strings, and a space sorts before a slash. Bump foliate-js to compare paths segment by segment with a numeric collator so a folder that is a prefix of a sibling sorts first, and add a regression test for the reported layout. Fixes #5745 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * chore: pin foliate-js to the squash-merged commit of readest/foliate-js#79 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * chore: bump foliate-js to latest main Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
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.
Problem
A CBZ chapter split across folders that share a chapter number, such as
Chapter 0060/andChapter 0060 (2)/, renders part 2 before part 1 (readest/readest#5745).Image paths are flattened into one list and sorted as plain strings. After the shared prefix
Chapter 0060, the comparison is" (2)/001.jpg"vs"/001.jpg", and a space (0x20) sorts before a slash (0x2F), so the(2)folder wins.Upstream's newer
.sort(new Intl.Collator([], { numeric: true }).compare)on whole paths does not fix this either: the collator still ranks the space-paren run before the slash (verified empirically).Fix
Compare paths segment by segment: split on
/, compare each segment with a numeric collator, and let the shorter path win at divergence so a folder that is a prefix of a sibling sorts first. Numeric collation also fixes unpadded page names (2.jpgbefore10.jpg).Order produced for the report's layout:
Tests
Regression test lands in the app repo (
src/__tests__/foliate-cbz-page-order.test.ts) alongside the submodule bump; it fails against the old sort and passes with this change.🤖 Generated with Claude Code