-
Notifications
You must be signed in to change notification settings - Fork 163
Filter out topics that aren't available in the page's language #96
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
franklinsch
merged 3 commits into
swiftlang:main
from
franklinsch:filter-topics-languages
Mar 11, 2022
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -608,6 +608,9 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate { | |
| tutorials: [SemanticResult<Tutorial>], | ||
| tutorialArticles: [SemanticResult<TutorialArticle>], | ||
| bundle: DocumentationBundle) { | ||
|
|
||
| let sourceLanguages = soleRootModuleReference?.sourceLanguages ?? [.swift] | ||
|
|
||
| // Technologies | ||
|
|
||
| for technologyResult in technologies { | ||
|
|
@@ -621,15 +624,30 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate { | |
| // Add to document map | ||
| documentLocationMap[url] = technologyResult.topicGraphNode.reference | ||
|
|
||
| let sourceLanguage = SourceLanguage.swift | ||
| let node = DocumentationNode(reference: technologyResult.topicGraphNode.reference, kind: .technology, sourceLanguage: sourceLanguage, name: .conceptual(title: technology.intro.title), markup: technology.originalMarkup, semantic: technology) | ||
| documentationCache[technologyResult.topicGraphNode.reference] = node | ||
| let technologyReference = technologyResult.topicGraphNode.reference.withSourceLanguages(sourceLanguages) | ||
|
|
||
| let technologyNode = DocumentationNode( | ||
| reference: technologyReference, | ||
| kind: .technology, | ||
| sourceLanguage: Self.defaultLanguage(in: sourceLanguages), | ||
| availableSourceLanguages: sourceLanguages, | ||
| name: .conceptual(title: technology.intro.title), | ||
| markup: technology.originalMarkup, | ||
| semantic: technology | ||
| ) | ||
| documentationCache[technologyReference] = technologyNode | ||
|
|
||
| // Update the reference in the topic graph with the technology's available languages. | ||
| topicGraph.updateReference( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! This looks great- much easier for me to follow. |
||
| technologyResult.topicGraphNode.reference, | ||
| newReference: technologyReference | ||
| ) | ||
|
|
||
| let anonymousVolumeName = "$volume" | ||
|
|
||
| for volume in technology.volumes { | ||
| // Graph node: Volume | ||
| let volumeReference = node.reference.appendingPath(volume.name ?? anonymousVolumeName) | ||
| let volumeReference = technologyNode.reference.appendingPath(volume.name ?? anonymousVolumeName) | ||
| let volumeNode = TopicGraph.Node(reference: volumeReference, kind: .volume, source: .file(url: url), title: volume.name ?? anonymousVolumeName) | ||
| topicGraph.addNode(volumeNode) | ||
|
|
||
|
|
@@ -640,7 +658,7 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate { | |
| // Graph node: Module | ||
| let baseNodeReference: ResolvedTopicReference | ||
| if volume.name == nil { | ||
| baseNodeReference = node.reference | ||
| baseNodeReference = technologyNode.reference | ||
| } else { | ||
| baseNodeReference = volumeNode.reference | ||
| } | ||
|
|
@@ -678,8 +696,24 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate { | |
| // Add to document map | ||
| documentLocationMap[url] = tutorialResult.topicGraphNode.reference | ||
|
|
||
| let tutorialNode = DocumentationNode(reference: tutorialResult.topicGraphNode.reference, kind: .tutorial, sourceLanguage: tutorialResult.topicGraphNode.reference.sourceLanguage, name: .conceptual(title: tutorial.intro.title), markup: tutorial.originalMarkup, semantic: tutorial) | ||
| documentationCache[tutorialResult.topicGraphNode.reference] = tutorialNode | ||
| let tutorialReference = tutorialResult.topicGraphNode.reference.withSourceLanguages(sourceLanguages) | ||
|
|
||
| let tutorialNode = DocumentationNode( | ||
| reference: tutorialReference, | ||
| kind: .tutorial, | ||
| sourceLanguage: Self.defaultLanguage(in: sourceLanguages), | ||
| availableSourceLanguages: sourceLanguages, | ||
| name: .conceptual(title: tutorial.intro.title), | ||
| markup: tutorial.originalMarkup, | ||
| semantic: tutorial | ||
| ) | ||
| documentationCache[tutorialReference] = tutorialNode | ||
|
|
||
| // Update the reference in the topic graph with the tutorial's available languages. | ||
| topicGraph.updateReference( | ||
| tutorialResult.topicGraphNode.reference, | ||
| newReference: tutorialReference | ||
| ) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -695,9 +729,25 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate { | |
|
|
||
| // Add to document map | ||
| documentLocationMap[url] = articleResult.topicGraphNode.reference | ||
|
|
||
| let articleReference = articleResult.topicGraphNode.reference.withSourceLanguages(sourceLanguages) | ||
|
|
||
| let articleNode = DocumentationNode( | ||
| reference: articleReference, | ||
| kind: .tutorialArticle, | ||
| sourceLanguage: Self.defaultLanguage(in: sourceLanguages), | ||
| availableSourceLanguages: sourceLanguages, | ||
| name: .conceptual(title: article.title ?? ""), | ||
| markup: article.originalMarkup, | ||
| semantic: article | ||
| ) | ||
| documentationCache[articleReference] = articleNode | ||
|
|
||
| let articleNode = DocumentationNode(reference: articleResult.topicGraphNode.reference, kind: .tutorialArticle, sourceLanguage: articleResult.topicGraphNode.reference.sourceLanguage, name: .conceptual(title: article.title ?? ""), markup: article.originalMarkup, semantic: article) | ||
| documentationCache[articleResult.topicGraphNode.reference] = articleNode | ||
| // Update the reference in the topic graph with the article's available languages. | ||
| topicGraph.updateReference( | ||
| articleResult.topicGraphNode.reference, | ||
| newReference: articleReference | ||
| ) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1722,13 +1772,7 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate { | |
|
|
||
| // If available source languages are provided and it contains Swift, use Swift as the default language of | ||
| // the article. | ||
| let defaultSourceLanguage = availableSourceLanguages.map { availableSourceLanguages in | ||
| if availableSourceLanguages.contains(.swift) { | ||
| return .swift | ||
| } else { | ||
| return availableSourceLanguages.first ?? .swift | ||
| } | ||
| } ?? SourceLanguage.swift | ||
| let defaultSourceLanguage = defaultLanguage(in: availableSourceLanguages) | ||
|
|
||
| let reference = ResolvedTopicReference( | ||
| bundleIdentifier: bundle.identifier, | ||
|
|
@@ -2417,13 +2461,7 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate { | |
| /// | ||
| /// Adds any non-resolving reference to the `allCandidateURLs` collection. | ||
| func attemptToResolve(_ reference: ResolvedTopicReference) -> TopicReferenceResolutionResult? { | ||
| if topicGraph.nodeWithReference(reference) != nil { | ||
| let resolved = ResolvedTopicReference( | ||
| bundleIdentifier: referenceBundleIdentifier, | ||
| path: reference.url.path, | ||
| fragment: reference.fragment, | ||
| sourceLanguages: reference.sourceLanguages | ||
| ) | ||
| if let resolved = topicGraph.nodeWithReference(reference)?.reference { | ||
| // If resolving a symbol link, only match symbol nodes. | ||
| if isCurrentlyResolvingSymbolLink && !(documentationCache[resolved]?.semantic is Symbol) { | ||
| allCandidateURLs.append(reference.url) | ||
|
|
@@ -2698,6 +2736,16 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate { | |
| } | ||
| .joined() | ||
| } | ||
|
|
||
| private static func defaultLanguage(in sourceLanguages: Set<SourceLanguage>?) -> SourceLanguage { | ||
| sourceLanguages.map { sourceLanguages in | ||
| if sourceLanguages.contains(.swift) { | ||
| return .swift | ||
| } else { | ||
| return sourceLanguages.first ?? .swift | ||
| } | ||
| } ?? SourceLanguage.swift | ||
| } | ||
| } | ||
|
|
||
| // MARK: - DocumentationCurator | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.