-
Notifications
You must be signed in to change notification settings - Fork 163
Fix api collection icon rendering #1343
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -165,7 +165,7 @@ extension LinkDestinationSummary { | |
|
|
||
| /// Create a topic render render reference for this link summary and its content variants. | ||
| func makeTopicRenderReference() -> TopicRenderReference { | ||
| let (kind, role) = DocumentationContentRenderer.renderKindAndRole(kind, semantic: nil) | ||
| let (kind, role) = DocumentationContentRenderer.renderKindAndRole(kind, semantic: nil, linkSummary: self) | ||
|
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. Question: Is there some other value about the link summary that we can use to determine if it's an API collection?
Contributor
Author
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. After analyzing the
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. The
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. Is there another
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. I believe |
||
|
|
||
| var titleVariants = VariantCollection(defaultValue: title) | ||
| var abstractVariants = VariantCollection(defaultValue: abstract ?? []) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -247,7 +247,7 @@ public class DocumentationContentRenderer { | |
| return true | ||
| } | ||
|
|
||
| static func renderKindAndRole(_ kind: DocumentationNode.Kind?, semantic: Semantic?) -> (RenderNode.Kind, String) { | ||
| static func renderKindAndRole(_ kind: DocumentationNode.Kind?, semantic: Semantic? = nil, linkSummary: LinkDestinationSummary? = nil) -> (RenderNode.Kind, String) { | ||
|
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. If I understand this correctly, this method is not expected to receive both a semantic and a link summary because one represents a local page and the other represents an external page. If we need a version that accepts a link summary we could consider having either a separate overload (that calls into a private common implementation) or a parameter that can be either a Semantic or a LinkDestinationSummary.
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. If it's not expected to pass both semantic and linkSummary at the same invocation call, let's split the method into two making them an overload. The original static func renderKindAndRole(_ kind: DocumentationNode.Kind?, semantic: Semantic?) -> (RenderNode.Kind, String) {and the overload static func renderKindAndRole(_ kind: DocumentationNode.Kind?, linkSummary: LinkDestinationSummary?) -> (RenderNode.Kind, String) {Then the common logic can be encapsulated in another function. |
||
| guard let kind else { | ||
| return (.article, role(for: .article).rawValue) | ||
| } | ||
|
|
@@ -270,6 +270,9 @@ public class DocumentationContentRenderer { | |
| default: | ||
| if let article = semantic as? Article { | ||
| return (.article, roleForArticle(article, nodeKind: kind).rawValue) | ||
| } else if kind == .article, let summary = linkSummary, summary.taskGroups != nil { | ||
|
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. The task groups of an link summary isn't a value that external documentation sources have to provide—and DocC doesn't include it in its link summaries unless specifically configured to do so—so it can't be reliably used to determine if an external page is an API collection or not. |
||
| // For external references: Articles with task groups are API Collections and should have collectionGroup role | ||
| return (.article, Self.role(for: .collectionGroup).rawValue) | ||
| } else { | ||
| return (.article, role) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -131,6 +131,24 @@ class DocumentationContentRendererTests: XCTestCase { | |
| ] | ||
| ) | ||
| } | ||
|
|
||
| func testRenderKindAndRoleForAPICollection() throws { | ||
|
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. Test looks good, but you might want to add another test for the case when And what should happen if |
||
| // Articles with task groups should get collectionGroup role for external references | ||
| let apiCollectionSummary = LinkDestinationSummary( | ||
| kind: .article, | ||
| language: .swift, | ||
| relativePresentationURL: URL(string: "/documentation/test/external/api-collection")!, | ||
| referenceURL: URL(string: "doc://com.example.test/documentation/test/external/api-collection")!, | ||
| title: "External API Collection", | ||
| availableLanguages: [.swift], | ||
| taskGroups: [LinkDestinationSummary.TaskGroup(title: "Symbols", identifiers: ["doc://com.example.test/symbol1"])], | ||
| variants: [] | ||
| ) | ||
|
|
||
| let (kind, role) = DocumentationContentRenderer.renderKindAndRole(.article, semantic: nil, linkSummary: apiCollectionSummary) | ||
| XCTAssertEqual(kind, RenderNode.Kind.article) | ||
| XCTAssertEqual(role, "collectionGroup") | ||
| } | ||
| } | ||
|
|
||
| private extension DocumentationDataVariantsTrait { | ||
|
|
||
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.
You set the default value for
semanticto be nil, so there's no need to pass that in here now.