Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ All notable changes to this project will be documented in this file. Take a look

* 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).

### Changed

#### Streamer

* EPUB series added with Calibre now take precedence over the native EPUB ones in the `belongsToSeries` RWPM property.

### Fixed

#### Streamer
Expand Down
15 changes: 14 additions & 1 deletion Sources/Shared/Toolkit/URL/RelativeURL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,23 @@ public struct RelativeURL: URLProtocol, Hashable {
resolvedComponents.fragment = otherComponents.fragment
resolvedComponents.query = otherComponents.query

guard let resolvedURL = resolvedComponents.url?.standardized else {
guard var resolvedURL = resolvedComponents.url?.standardized else {
return nil
}

// Since iOS 26, resolving an `other` URL moving upwards in the
// hierarchy can result in an URL starting with a `/`, which is not
// what we want.
if
!path.hasPrefix("/"),
!other.path.hasPrefix("/"),
resolvedURL.path.hasPrefix("/"),
var components = URLComponents(url: resolvedURL, resolvingAgainstBaseURL: true)
{
components.path.removeFirst()
resolvedURL = components.url ?? resolvedURL
}

return RelativeURL(url: resolvedURL)
}

Expand Down
30 changes: 16 additions & 14 deletions Sources/Streamer/Parser/EPUB/EPUBMetadataParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,21 @@ final class EPUBMetadataParser: Loggable {

/// https://github.com/readium/architecture/blob/master/streamer/parser/metadata.md#collections-and-series
private lazy var belongsToSeries: [Metadata.Collection] = {
let calibrePosition = metas["series_index", in: .calibre].first
.flatMap { Double($0.content) }

let calibreSeries = metas["series", in: .calibre]
.map { meta in
Metadata.Collection(
name: meta.content,
position: calibrePosition
)
}

if !calibreSeries.isEmpty {
return calibreSeries
}

let epub3Series = metas["belongs-to-collection"]
// `collection-type` should be "series"
.filter { meta in
Expand All @@ -459,20 +474,7 @@ final class EPUBMetadataParser: Loggable {
}
.compactMap(collection(from:))

if !epub3Series.isEmpty {
return epub3Series
}

let epub2Position = metas["series_index", in: .calibre].first
.flatMap { Double($0.content) }

return metas["series", in: .calibre]
.map { meta in
Metadata.Collection(
name: meta.content,
position: epub2Position
)
}
return epub3Series
}()

private func collection(from meta: OPFMeta) -> Metadata.Collection? {
Expand Down
1 change: 0 additions & 1 deletion Tests/SharedTests/Toolkit/URL/RelativeURLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ class RelativeURLTests: XCTestCase {
XCTAssertEqual(RelativeURL(string: "foo")!.removingLastPathSegment().string, "./")
XCTAssertEqual(RelativeURL(string: "foo/bar")!.removingLastPathSegment().string, "foo/")
XCTAssertEqual(RelativeURL(string: "foo/bar/")!.removingLastPathSegment().string, "foo/")
XCTAssertEqual(RelativeURL(string: "/")!.removingLastPathSegment().string, "/../")
XCTAssertEqual(RelativeURL(string: "/foo")!.removingLastPathSegment().string, "/")
XCTAssertEqual(RelativeURL(string: "/foo/bar")!.removingLastPathSegment().string, "/foo/")
XCTAssertEqual(RelativeURL(string: "/foo/bar/")!.removingLastPathSegment().string, "/foo/")
Expand Down