Skip to content

Commit 78ed602

Browse files
committed
Don't emit variants for article-only catalogs
For article-only catalogs, i.e., catalogs that use @TechnologyRoot, don't emit the variants array in the render node, so that renderers don't display the page's language, since it doesn't have a language. A longer-term fix here would be to not consider articles in article-only catalogs to be "Swift", and implement logic in RenderNodeTranslator to not emit variants information for language-less pages (github.com/swiftlang/issues/240). rdar://92758192
1 parent 0aac1c2 commit 78ed602

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

Sources/SwiftDocC/Infrastructure/DocumentationContext.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -1877,7 +1877,10 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
18771877
let reference = ResolvedTopicReference(
18781878
bundleIdentifier: bundle.identifier,
18791879
path: path,
1880-
sourceLanguages: availableSourceLanguages ?? [.swift]
1880+
sourceLanguages: availableSourceLanguages
1881+
// FIXME: Pages in article-only catalogs should not be inferred as "Swift" as a fallback
1882+
// (github.com/apple/swift-docc/issues/240).
1883+
?? [.swift]
18811884
)
18821885

18831886
let title = article.topicGraphNode.title

Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift

+8-1
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,14 @@ public struct RenderNodeTranslator: SemanticVisitor {
601601
collectedTopicReferences.append(contentsOf: hierarchyTranslator.collectedTopicReferences)
602602
node.hierarchy = hierarchy
603603

604-
node.variants = variants(for: documentationNode)
604+
// Emit variants only if we're not compiling an article-only catalog to prevent renderers from
605+
// advertising the page as "Swift", which is the language DocC assigns to pages in article only pages.
606+
// (github.com/apple/swift-docc/issues/240).
607+
if let topLevelModule = context.soleRootModuleReference,
608+
try! context.entity(with: topLevelModule).kind.isSymbol
609+
{
610+
node.variants = variants(for: documentationNode)
611+
}
605612

606613
if let abstract = article.abstractSection,
607614
let abstractContent = visitMarkup(abstract.content) as? [RenderInlineContent] {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2022 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See https://swift.org/LICENSE.txt for license information
8+
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
import XCTest
12+
@testable import SwiftDocC
13+
14+
class SemaToRenderNodeArticleOnlyCatalogTests: XCTestCase {
15+
func testDoesNotEmitVariantsForPagesInArticleOnlyCatalog() throws {
16+
for renderNode in try renderNodeConsumer(for: "BundleWithTechnologyRoot").allRenderNodes() {
17+
XCTAssertNil(renderNode.variants)
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)