Skip to content

Commit f649305

Browse files
Merge pull request #3095 from SwiftPackageIndex/stable-doc-paths-tweaks
Two small tweaks into the "Current" documentation PR before some bigger changes
2 parents 14bae75 + 4e86256 commit f649305

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

Sources/App/Controllers/PackageController+routes.swift

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,11 @@ enum PackageController {
121121
.init(archive: $0, isCurrent: $0.name == route.archive)
122122
}
123123

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)
137129

138130
// Try and parse the page and add our header, but fall back to the unprocessed page if it fails.
139131
guard let body = awsResponse.body,
@@ -463,10 +455,12 @@ extension PackageController {
463455

464456
extension PackageController {
465457
static func canonicalDocumentationUrl(from url: String,
466-
owner: String,
467-
repository: String,
458+
owner: String?,
459+
repository: String?,
468460
docVersion: DocVersion,
469-
toTarget target: DocumentationTarget) -> String? {
461+
toTarget target: DocumentationTarget?) -> String? {
462+
guard let owner, let repository, let target else { return nil }
463+
470464
// It's important to use `docVersion.reference` here to make sure we match with true reference urls and not ~
471465
let urlPrefix = "/\(owner)/\(repository)/\(docVersion.reference.pathEncoded)/"
472466
if case let .internal(canonicalReference, _) = target,

Sources/App/Views/DocumentationPageProcessor.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ struct DocumentationPageProcessor {
8282
try document.head()?.append(self.stylesheetLink)
8383
if let canonicalUrl = self.canonicalUrl {
8484
try document.head()?.append(
85-
// We should not use `url` here as some of the DocC JavaScript lowercases
86-
// both the `og:url` and `twitter:url` properties, if present. It is better
87-
// to have no `og:url` and `twitter:url` properties than incorrect ones.
85+
// We should not use Plot's `url` helper here as some of the DocC JavaScript
86+
// lowercases both the `og:url` and `twitter:url` properties, if present. It's
87+
// better to have no `og:url` and `twitter:url` properties than incorrect ones.
8888
Plot.Node.link(
8989
.rel(.canonical),
9090
.href(canonicalUrl)

0 commit comments

Comments
 (0)