-
Notifications
You must be signed in to change notification settings - Fork 146
Support external links in the navigator #1247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
anferbui
merged 6 commits into
swiftlang:main
from
anferbui:external-links-in-navigator
Jul 15, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6800bc8
External Render Node Support
anferbui 4aad541
External Render Node representation for the navigator
anferbui e8cd14a
Index external render nodes
anferbui 2ba8bb0
Consume external render nodes
anferbui 5ecb12a
Only add external nodes to index if manually curated in Topics section
anferbui 8d6607d
Propagate isExternal value to RenderIndex
anferbui File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
Sources/SwiftDocC/Infrastructure/Link Resolution/LinkResolver+NavigatorIndex.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/* | ||
This source file is part of the Swift.org open source project | ||
|
||
Copyright (c) 2025 Apple Inc. and the Swift project authors | ||
Licensed under Apache License v2.0 with Runtime Library Exception | ||
|
||
See https://swift.org/LICENSE.txt for license information | ||
See https://swift.org/CONTRIBUTORS.txt for Swift project authors | ||
*/ | ||
|
||
import Foundation | ||
import SymbolKit | ||
|
||
/// A rendering-friendly representation of a external node. | ||
package struct ExternalRenderNode { | ||
/// Underlying external entity backing this external node. | ||
private var externalEntity: LinkResolver.ExternalEntity | ||
|
||
/// The bundle identifier for this external node. | ||
private var bundleIdentifier: DocumentationBundle.Identifier | ||
|
||
init(externalEntity: LinkResolver.ExternalEntity, bundleIdentifier: DocumentationBundle.Identifier) { | ||
self.externalEntity = externalEntity | ||
self.bundleIdentifier = bundleIdentifier | ||
} | ||
|
||
/// The identifier of the external render node. | ||
package var identifier: ResolvedTopicReference { | ||
ResolvedTopicReference( | ||
bundleID: bundleIdentifier, | ||
path: externalEntity.topicRenderReference.url, | ||
sourceLanguages: externalEntity.sourceLanguages | ||
) | ||
} | ||
|
||
/// The kind of this documentation node. | ||
var kind: RenderNode.Kind { | ||
externalEntity.topicRenderReference.kind | ||
} | ||
|
||
/// The symbol kind of this documentation node. | ||
var symbolKind: SymbolGraph.Symbol.KindIdentifier? { | ||
// Symbol kind information is not available for external entities | ||
return nil | ||
} | ||
|
||
/// The additional "role" assigned to the symbol, if any | ||
/// | ||
/// This value is `nil` if the referenced page is not a symbol. | ||
var role: String? { | ||
externalEntity.topicRenderReference.role | ||
} | ||
|
||
/// The variants of the title. | ||
var titleVariants: VariantCollection<String> { | ||
externalEntity.topicRenderReference.titleVariants | ||
} | ||
|
||
/// The variants of the abbreviated declaration of the symbol to display in navigation. | ||
var navigatorTitleVariants: VariantCollection<[DeclarationRenderSection.Token]?> { | ||
externalEntity.topicRenderReference.navigatorTitleVariants | ||
} | ||
|
||
/// The variants of the abbreviated declaration of the symbol to display in links. | ||
var fragmentsVariants: VariantCollection<[DeclarationRenderSection.Token]?> { | ||
externalEntity.topicRenderReference.fragmentsVariants | ||
} | ||
|
||
/// Author provided images that represent this page. | ||
var images: [TopicImage] { | ||
externalEntity.topicRenderReference.images | ||
} | ||
|
||
/// The identifier of the external reference. | ||
var externalIdentifier: RenderReferenceIdentifier { | ||
externalEntity.topicRenderReference.identifier | ||
} | ||
|
||
/// List of variants of the same external node for various languages. | ||
var variants: [RenderNode.Variant]? { | ||
externalEntity.sourceLanguages.map { | ||
RenderNode.Variant(traits: [.interfaceLanguage($0.id)], paths: [externalEntity.topicRenderReference.url]) | ||
} | ||
} | ||
} | ||
|
||
/// A language specific representation of an external render node value for building a navigator index. | ||
struct NavigatorExternalRenderNode: NavigatorIndexableRenderNodeRepresentation { | ||
var identifier: ResolvedTopicReference | ||
var externalIdentifier: RenderReferenceIdentifier | ||
var kind: RenderNode.Kind | ||
var metadata: ExternalRenderNodeMetadataRepresentation | ||
|
||
// Values that don't affect how the node is rendered in the sidebar. | ||
// These are needed to conform to the navigator indexable protocol. | ||
var references: [String : any RenderReference] = [:] | ||
var sections: [any RenderSection] = [] | ||
var topicSections: [TaskGroupRenderSection] = [] | ||
var defaultImplementationsSections: [TaskGroupRenderSection] = [] | ||
|
||
init(renderNode: ExternalRenderNode, trait: RenderNode.Variant.Trait? = nil) { | ||
// Compute the source language of the node based on the trait to know which variant to apply. | ||
let traitLanguage = if case .interfaceLanguage(let id) = trait { | ||
SourceLanguage(id: id) | ||
} else { | ||
renderNode.identifier.sourceLanguage | ||
} | ||
let traits = trait.map { [$0] } ?? [] | ||
|
||
self.identifier = renderNode.identifier.withSourceLanguages(Set(arrayLiteral: traitLanguage)) | ||
self.kind = renderNode.kind | ||
self.externalIdentifier = renderNode.externalIdentifier | ||
|
||
self.metadata = ExternalRenderNodeMetadataRepresentation( | ||
title: renderNode.titleVariants.value(for: traits), | ||
navigatorTitle: renderNode.navigatorTitleVariants.value(for: traits), | ||
externalID: renderNode.externalIdentifier.identifier, | ||
role: renderNode.role, | ||
symbolKind: renderNode.symbolKind?.identifier, | ||
images: renderNode.images | ||
) | ||
} | ||
} | ||
|
||
/// A language specific representation of a render metadata value for building an external navigator index. | ||
struct ExternalRenderNodeMetadataRepresentation: NavigatorIndexableRenderMetadataRepresentation { | ||
var title: String? | ||
var navigatorTitle: [DeclarationRenderSection.Token]? | ||
var externalID: String? | ||
var role: String? | ||
var symbolKind: String? | ||
var images: [TopicImage] | ||
|
||
// Values that we have insufficient information to derive. | ||
// These are needed to conform to the navigator indexable metadata protocol. | ||
// | ||
// The fragments that we get as part of the external link are the full declaration fragments. | ||
// These are too verbose for the navigator, so instead of using them, we rely on the title, navigator title and symbol kind instead. | ||
// | ||
// The role heading is used to identify Property Lists. | ||
// The value being missing is used for computing the final navigator title. | ||
// | ||
// The platforms are used for generating the availability index, | ||
// but doesn't affect how the node is rendered in the sidebar. | ||
var fragments: [DeclarationRenderSection.Token]? = nil | ||
var roleHeading: String? = nil | ||
var platforms: [AvailabilityRenderItem]? = nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created this
package
-level protocol so that we don't have to make a breaking API change topublic
protocolConvertOutputConsumer
.