@@ -121,19 +121,11 @@ enum PackageController {
121
121
. init( archive: $0, isCurrent: $0. name == route. archive)
122
122
}
123
123
124
- let canonicalUrl : String ? = {
125
- guard let canonicalOwner = documentationMetadata. owner,
126
- let canonicalRepository = documentationMetadata. repository,
127
- let canonicalTarget = documentationMetadata. canonicalTarget
128
- else { return nil }
129
-
130
- return Self . canonicalDocumentationUrl ( from: " \( req. url) " ,
131
- owner: canonicalOwner,
132
- repository: canonicalRepository,
133
- docVersion: route. docVersion,
134
- toTarget: canonicalTarget)
135
- } ( )
136
-
124
+ let canonicalUrl = Self . canonicalDocumentationUrl ( from: " \( req. url) " ,
125
+ owner: documentationMetadata. owner,
126
+ repository: documentationMetadata. repository,
127
+ docVersion: route. docVersion,
128
+ toTarget: documentationMetadata. canonicalTarget)
137
129
138
130
// Try and parse the page and add our header, but fall back to the unprocessed page if it fails.
139
131
guard let body = awsResponse. body,
@@ -463,10 +455,12 @@ extension PackageController {
463
455
464
456
extension PackageController {
465
457
static func canonicalDocumentationUrl( from url: String ,
466
- owner: String ,
467
- repository: String ,
458
+ owner: String ? ,
459
+ repository: String ? ,
468
460
docVersion: DocVersion ,
469
- toTarget target: DocumentationTarget ) -> String ? {
461
+ toTarget target: DocumentationTarget ? ) -> String ? {
462
+ guard let owner, let repository, let target else { return nil }
463
+
470
464
// It's important to use `docVersion.reference` here to make sure we match with true reference urls and not ~
471
465
let urlPrefix = " / \( owner) / \( repository) / \( docVersion. reference. pathEncoded) / "
472
466
if case let . internal( canonicalReference, _) = target,
0 commit comments