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