Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sources/SwiftDocC/Infrastructure/DocumentationContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2048,13 +2048,14 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
in bundle: DocumentationBundle
) -> DocumentationContext.Articles {
articles.map { article in
let kind = article.value.metadata?.pageKind?.kind.documentationNodeKind ?? .article
guard let (documentation, title) = DocumentationContext.documentationNodeAndTitle(
for: article,
// By default, articles are available in the languages the module that's being documented
// is available in. It's possible to override that behavior using the `@SupportedLanguage`
// directive though; see its documentation for more details.
availableSourceLanguages: soleRootModuleReference.map { sourceLanguages(for: $0) },
kind: .article,
kind: kind,
in: bundle
) else {
return article
Expand Down
9 changes: 9 additions & 0 deletions Sources/SwiftDocC/Semantics/Metadata/PageKind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ extension Metadata {
return "Sample Code"
}
}

var documentationNodeKind: DocumentationNode.Kind {
switch self {
case .article:
return .article
case .sampleCode:
return .sampleCode
}
}
}

/// The page kind to apply to the page.
Expand Down
40 changes: 40 additions & 0 deletions Tests/SwiftDocCUtilitiesTests/ConvertActionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,19 @@ class ConvertActionTests: XCTestCase {
"""
),

TextFile(name: "SampleArticle.md", utf8Content: """
# Sample Article

@Metadata {
@PageKind(sampleCode)
}

Sample abstract.

Discussion content
"""
),

// A module page
TextFile(name: "TestBed.md", utf8Content: """
# ``TestBed``
Expand Down Expand Up @@ -1046,6 +1059,15 @@ class ConvertActionTests: XCTestCase {
headings: ["Overview", "Article Section"],
rawIndexableTextContent: "Article abstract. Overview Discussion content Article Section This is another section of the article."
)
case "/documentation/TestBundle/SampleArticle":
return IndexingRecord(
kind: .article,
location: .topLevelPage(reference),
title: "Sample Article",
summary: "Sample abstract.",
headings: ["Overview"],
rawIndexableTextContent: "Sample abstract. Overview Discussion content"
)
default:
XCTFail("Encountered unexpected page '\(reference)'")
return nil
Expand All @@ -1064,6 +1086,7 @@ class ConvertActionTests: XCTestCase {
abstract: "TestBed abstract.",
taskGroups: [
.init(title: "Basics", identifiers: ["doc://com.test.example/documentation/TestBundle/Article"]),
.init(title: "Articles", identifiers: ["doc://com.test.example/documentation/TestBundle/SampleArticle"]),
.init(title: "Structures", identifiers: ["doc://com.test.example/documentation/TestBed/A"]),
],
usr: "TestBed",
Expand Down Expand Up @@ -1109,6 +1132,23 @@ class ConvertActionTests: XCTestCase {
redirects: nil
),
]
case "/documentation/TestBundle/SampleArticle":
return [
LinkDestinationSummary(
kind: .sampleCode,
relativePresentationURL: URL(string: "/documentation/testbundle/samplearticle")!,
referenceURL: reference.url,
title: "Sample Article",
language: .swift,
abstract: "Sample abstract.",
taskGroups: [],
availableLanguages: [.swift],
platforms: nil,
topicImages: nil,
references: nil,
redirects: nil
)
]
default:
XCTFail("Encountered unexpected page '\(reference)'")
return []
Expand Down