Skip to content

Commit 1f66cc4

Browse files
authored
Change the precedence of EPUB series (#643)
1 parent d986782 commit 1f66cc4

File tree

4 files changed

+36
-16
lines changed

4 files changed

+36
-16
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ All notable changes to this project will be documented in this file. Take a look
1616

1717
* The Presentation Hints properties are deprecated from the Readium Web Publication Manifest models. [See the official documentation](https://readium.org/webpub-manifest/profiles/epub.html#appendix-b---deprecated-properties).
1818

19+
### Changed
20+
21+
#### Streamer
22+
23+
* EPUB series added with Calibre now take precedence over the native EPUB ones in the `belongsToSeries` RWPM property.
24+
1925
### Fixed
2026

2127
#### Streamer

Sources/Shared/Toolkit/URL/RelativeURL.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,23 @@ public struct RelativeURL: URLProtocol, Hashable {
6969
resolvedComponents.fragment = otherComponents.fragment
7070
resolvedComponents.query = otherComponents.query
7171

72-
guard let resolvedURL = resolvedComponents.url?.standardized else {
72+
guard var resolvedURL = resolvedComponents.url?.standardized else {
7373
return nil
7474
}
7575

76+
// Since iOS 26, resolving an `other` URL moving upwards in the
77+
// hierarchy can result in an URL starting with a `/`, which is not
78+
// what we want.
79+
if
80+
!path.hasPrefix("/"),
81+
!other.path.hasPrefix("/"),
82+
resolvedURL.path.hasPrefix("/"),
83+
var components = URLComponents(url: resolvedURL, resolvingAgainstBaseURL: true)
84+
{
85+
components.path.removeFirst()
86+
resolvedURL = components.url ?? resolvedURL
87+
}
88+
7689
return RelativeURL(url: resolvedURL)
7790
}
7891

Sources/Streamer/Parser/EPUB/EPUBMetadataParser.swift

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,21 @@ final class EPUBMetadataParser: Loggable {
449449

450450
/// https://github.com/readium/architecture/blob/master/streamer/parser/metadata.md#collections-and-series
451451
private lazy var belongsToSeries: [Metadata.Collection] = {
452+
let calibrePosition = metas["series_index", in: .calibre].first
453+
.flatMap { Double($0.content) }
454+
455+
let calibreSeries = metas["series", in: .calibre]
456+
.map { meta in
457+
Metadata.Collection(
458+
name: meta.content,
459+
position: calibrePosition
460+
)
461+
}
462+
463+
if !calibreSeries.isEmpty {
464+
return calibreSeries
465+
}
466+
452467
let epub3Series = metas["belongs-to-collection"]
453468
// `collection-type` should be "series"
454469
.filter { meta in
@@ -459,20 +474,7 @@ final class EPUBMetadataParser: Loggable {
459474
}
460475
.compactMap(collection(from:))
461476

462-
if !epub3Series.isEmpty {
463-
return epub3Series
464-
}
465-
466-
let epub2Position = metas["series_index", in: .calibre].first
467-
.flatMap { Double($0.content) }
468-
469-
return metas["series", in: .calibre]
470-
.map { meta in
471-
Metadata.Collection(
472-
name: meta.content,
473-
position: epub2Position
474-
)
475-
}
477+
return epub3Series
476478
}()
477479

478480
private func collection(from meta: OPFMeta) -> Metadata.Collection? {

Tests/SharedTests/Toolkit/URL/RelativeURLTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ class RelativeURLTests: XCTestCase {
129129
XCTAssertEqual(RelativeURL(string: "foo")!.removingLastPathSegment().string, "./")
130130
XCTAssertEqual(RelativeURL(string: "foo/bar")!.removingLastPathSegment().string, "foo/")
131131
XCTAssertEqual(RelativeURL(string: "foo/bar/")!.removingLastPathSegment().string, "foo/")
132-
XCTAssertEqual(RelativeURL(string: "/")!.removingLastPathSegment().string, "/../")
133132
XCTAssertEqual(RelativeURL(string: "/foo")!.removingLastPathSegment().string, "/")
134133
XCTAssertEqual(RelativeURL(string: "/foo/bar")!.removingLastPathSegment().string, "/foo/")
135134
XCTAssertEqual(RelativeURL(string: "/foo/bar/")!.removingLastPathSegment().string, "/foo/")

0 commit comments

Comments
 (0)