Skip to content

Commit 40805b0

Browse files
committed
Encode absolute presentation URL if present
Support for absolute URLs in link summaries was added in 7db36ad. It added support for absolute URLs when decoding a link summary, but not when encoding it: https://github.com/swiftlang/swift-docc/blob/cfcd96f0e992af2287661f6a26e8398096f6bc1e/Sources/SwiftDocC/LinkTargets/LinkDestinationSummary.swift#L772-L773 https://github.com/swiftlang/swift-docc/blob/cfcd96f0e992af2287661f6a26e8398096f6bc1e/Sources/SwiftDocC/LinkTargets/LinkDestinationSummary.swift#L728 Both are needed when using an external link resolver, as the external link resolver needs to encode the entity to send to DocC. Fixes rdar://164628218.
1 parent e96fa7a commit 40805b0

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

Sources/SwiftDocC/LinkTargets/LinkDestinationSummary.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ extension LinkDestinationSummary {
726726
} else {
727727
try container.encode(kind, forKey: .kind)
728728
}
729-
try container.encode(relativePresentationURL, forKey: .relativePresentationURL)
729+
try container.encode(absolutePresentationURL ?? relativePresentationURL, forKey: .relativePresentationURL)
730730
try container.encode(referenceURL, forKey: .referenceURL)
731731
try container.encode(title, forKey: .title)
732732
try container.encodeIfPresent(abstract, forKey: .abstract)

Tests/SwiftDocCTests/Infrastructure/ExternalReferenceResolverTests.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,10 @@ class ExternalReferenceResolverTests: XCTestCase {
14201420
""".utf8))
14211421
XCTAssertEqual(externalEntity.relativePresentationURL.absoluteString, "/path/to/something")
14221422
XCTAssertEqual(externalEntity.absolutePresentationURL?.absoluteString, "https://com.example/path/to/something")
1423-
1423+
1424+
// Test that encoding the link summary preserves the absolute URL
1425+
try assertRoundTripCoding(externalEntity)
1426+
14241427
let resolver = Resolver(entityToReturn: externalEntity)
14251428

14261429
var configuration = DocumentationContext.Configuration()

0 commit comments

Comments
 (0)