@@ -608,6 +608,9 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
608608 tutorials: [ SemanticResult < Tutorial > ] ,
609609 tutorialArticles: [ SemanticResult < TutorialArticle > ] ,
610610 bundle: DocumentationBundle ) {
611+
612+ let sourceLanguages = soleRootModuleReference? . sourceLanguages ?? [ . swift]
613+
611614 // Technologies
612615
613616 for technologyResult in technologies {
@@ -621,15 +624,30 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
621624 // Add to document map
622625 documentLocationMap [ url] = technologyResult. topicGraphNode. reference
623626
624- let sourceLanguage = SourceLanguage . swift
625- let node = DocumentationNode ( reference: technologyResult. topicGraphNode. reference, kind: . technology, sourceLanguage: sourceLanguage, name: . conceptual( title: technology. intro. title) , markup: technology. originalMarkup, semantic: technology)
626- documentationCache [ technologyResult. topicGraphNode. reference] = node
627+ let technologyReference = technologyResult. topicGraphNode. reference. withSourceLanguages ( sourceLanguages)
628+
629+ let technologyNode = DocumentationNode (
630+ reference: technologyReference,
631+ kind: . technology,
632+ sourceLanguage: Self . defaultLanguage ( in: sourceLanguages) ,
633+ availableSourceLanguages: sourceLanguages,
634+ name: . conceptual( title: technology. intro. title) ,
635+ markup: technology. originalMarkup,
636+ semantic: technology
637+ )
638+ documentationCache [ technologyReference] = technologyNode
639+
640+ // Update the reference in the topic graph with the technology's available languages.
641+ topicGraph. updateReference (
642+ technologyResult. topicGraphNode. reference,
643+ newReference: technologyReference
644+ )
627645
628646 let anonymousVolumeName = " $volume "
629647
630648 for volume in technology. volumes {
631649 // Graph node: Volume
632- let volumeReference = node . reference. appendingPath ( volume. name ?? anonymousVolumeName)
650+ let volumeReference = technologyNode . reference. appendingPath ( volume. name ?? anonymousVolumeName)
633651 let volumeNode = TopicGraph . Node ( reference: volumeReference, kind: . volume, source: . file( url: url) , title: volume. name ?? anonymousVolumeName)
634652 topicGraph. addNode ( volumeNode)
635653
@@ -640,7 +658,7 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
640658 // Graph node: Module
641659 let baseNodeReference : ResolvedTopicReference
642660 if volume. name == nil {
643- baseNodeReference = node . reference
661+ baseNodeReference = technologyNode . reference
644662 } else {
645663 baseNodeReference = volumeNode. reference
646664 }
@@ -678,8 +696,24 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
678696 // Add to document map
679697 documentLocationMap [ url] = tutorialResult. topicGraphNode. reference
680698
681- 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)
682- documentationCache [ tutorialResult. topicGraphNode. reference] = tutorialNode
699+ let tutorialReference = tutorialResult. topicGraphNode. reference. withSourceLanguages ( sourceLanguages)
700+
701+ let tutorialNode = DocumentationNode (
702+ reference: tutorialReference,
703+ kind: . tutorial,
704+ sourceLanguage: Self . defaultLanguage ( in: sourceLanguages) ,
705+ availableSourceLanguages: sourceLanguages,
706+ name: . conceptual( title: tutorial. intro. title) ,
707+ markup: tutorial. originalMarkup,
708+ semantic: tutorial
709+ )
710+ documentationCache [ tutorialReference] = tutorialNode
711+
712+ // Update the reference in the topic graph with the tutorial's available languages.
713+ topicGraph. updateReference (
714+ tutorialResult. topicGraphNode. reference,
715+ newReference: tutorialReference
716+ )
683717 }
684718 }
685719
@@ -695,9 +729,25 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
695729
696730 // Add to document map
697731 documentLocationMap [ url] = articleResult. topicGraphNode. reference
732+
733+ let articleReference = articleResult. topicGraphNode. reference. withSourceLanguages ( sourceLanguages)
734+
735+ let articleNode = DocumentationNode (
736+ reference: articleReference,
737+ kind: . tutorialArticle,
738+ sourceLanguage: Self . defaultLanguage ( in: sourceLanguages) ,
739+ availableSourceLanguages: sourceLanguages,
740+ name: . conceptual( title: article. title ?? " " ) ,
741+ markup: article. originalMarkup,
742+ semantic: article
743+ )
744+ documentationCache [ articleReference] = articleNode
698745
699- let articleNode = DocumentationNode ( reference: articleResult. topicGraphNode. reference, kind: . tutorialArticle, sourceLanguage: articleResult. topicGraphNode. reference. sourceLanguage, name: . conceptual( title: article. title ?? " " ) , markup: article. originalMarkup, semantic: article)
700- documentationCache [ articleResult. topicGraphNode. reference] = articleNode
746+ // Update the reference in the topic graph with the article's available languages.
747+ topicGraph. updateReference (
748+ articleResult. topicGraphNode. reference,
749+ newReference: articleReference
750+ )
701751 }
702752 }
703753
@@ -1722,13 +1772,7 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
17221772
17231773 // If available source languages are provided and it contains Swift, use Swift as the default language of
17241774 // the article.
1725- let defaultSourceLanguage = availableSourceLanguages. map { availableSourceLanguages in
1726- if availableSourceLanguages. contains ( . swift) {
1727- return . swift
1728- } else {
1729- return availableSourceLanguages. first ?? . swift
1730- }
1731- } ?? SourceLanguage . swift
1775+ let defaultSourceLanguage = defaultLanguage ( in: availableSourceLanguages)
17321776
17331777 let reference = ResolvedTopicReference (
17341778 bundleIdentifier: bundle. identifier,
@@ -2692,6 +2736,16 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
26922736 }
26932737 . joined ( )
26942738 }
2739+
2740+ private static func defaultLanguage( in sourceLanguages: Set < SourceLanguage > ? ) -> SourceLanguage {
2741+ sourceLanguages. map { sourceLanguages in
2742+ if sourceLanguages. contains ( . swift) {
2743+ return . swift
2744+ } else {
2745+ return sourceLanguages. first ?? . swift
2746+ }
2747+ } ?? SourceLanguage . swift
2748+ }
26952749}
26962750
26972751// MARK: - DocumentationCurator
0 commit comments