Skip to content

Commit 9c11d85

Browse files
committed
Add identifierItems for TaskGroupRenderSection
1 parent 79d268e commit 9c11d85

File tree

2 files changed

+54
-15
lines changed

2 files changed

+54
-15
lines changed

Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift

+9-7
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ public struct RenderNodeTranslator: SemanticVisitor {
10381038
title: group.heading?.plainText,
10391039
abstract: abstractContent,
10401040
discussion: discussion,
1041-
identifiers: group.links.compactMap { link in
1041+
identifierItems: group.links.compactMap { link in
10421042
switch link {
10431043
case let link as Link:
10441044
if !allowExternalLinks {
@@ -1060,12 +1060,13 @@ public struct RenderNodeTranslator: SemanticVisitor {
10601060
case let RenderInlineContent.reference(
10611061
identifier: identifier,
10621062
isActive: _,
1063-
overridingTitle: _,
1063+
overridingTitle: overridingTitle,
10641064
overridingTitleInlineContent: _
10651065
) = renderReference
10661066
{
1067-
return isTopicAvailableInAllowedTraits(identifier: identifier.identifier)
1068-
? identifier.identifier : nil
1067+
let identifier = identifier.identifier
1068+
return isTopicAvailableInAllowedTraits(identifier: identifier)
1069+
? TaskGroupRenderSection.IdentifierItem(identifier: identifier, overrideTitle: overridingTitle) : nil
10691070
}
10701071
case let link as SymbolLink:
10711072
if let referenceInlines = contentCompiler.visitSymbolLink(link) as? [RenderInlineContent],
@@ -1080,12 +1081,13 @@ public struct RenderNodeTranslator: SemanticVisitor {
10801081
case let RenderInlineContent.reference(
10811082
identifier: identifier,
10821083
isActive: _,
1083-
overridingTitle: _,
1084+
overridingTitle: overridingTitle,
10841085
overridingTitleInlineContent: _
10851086
) = renderReference
10861087
{
1087-
return isTopicAvailableInAllowedTraits(identifier: identifier.identifier)
1088-
? identifier.identifier : nil
1088+
let identifier = identifier.identifier
1089+
return isTopicAvailableInAllowedTraits(identifier: identifier)
1090+
? TaskGroupRenderSection.IdentifierItem(identifier: identifier, overrideTitle: overridingTitle) : nil
10891091
}
10901092
default: break
10911093
}

Sources/SwiftDocC/Model/Rendering/Symbol/TaskGroupRenderSection.swift

+45-8
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,57 @@ public struct TaskGroupRenderSection: RenderSection {
1919
/// An optional discussion for the section.
2020
public let discussion: RenderSection?
2121
/// A list of topic graph references.
22-
public let identifiers: [String]
22+
@available(*, deprecated, message: "Please use identifierItems instead.")
23+
public var identifiers: [String] { identifierItems.map { $0.identifier } }
24+
/// A list of topic graph reference items
25+
public let identifierItems: [IdentifierItem]
2326
/// If true, this is an automatically generated group. If false, this is an authored group.
2427
public let generated: Bool
2528

29+
public struct IdentifierItem: Codable {
30+
public let identifier: String
31+
public let overrideTitle: String?
32+
33+
public init(identifier: String, overrideTitle: String? = nil) {
34+
self.identifier = identifier
35+
self.overrideTitle = overrideTitle
36+
}
37+
}
38+
2639
/// Creates a new task group.
2740
/// - Parameters:
2841
/// - title: An optional title for the section.
2942
/// - abstract: An optional abstract summary for the section.
3043
/// - discussion: An optional discussion for the section.
3144
/// - identifiers: A list of topic-graph references.
3245
/// - generated: If `true`, this is an automatically generated group. If `false`, this is an authored group.
46+
@available(*, deprecated, message: "Please use TaskGroupRenderSection.init(title:abstract:discussion:identifierItems:generated:) instead.")
3347
public init(title: String?, abstract: [RenderInlineContent]?, discussion: RenderSection?, identifiers: [String], generated: Bool = false) {
3448
self.title = title
3549
self.abstract = abstract
3650
self.discussion = discussion
37-
self.identifiers = identifiers
51+
self.identifierItems = identifiers.map { IdentifierItem(identifier: $0) }
52+
self.generated = generated
53+
}
54+
55+
/// Creates a new task group.
56+
/// - Parameters:
57+
/// - title: An optional title for the section.
58+
/// - abstract: An optional abstract summary for the section.
59+
/// - discussion: An optional discussion for the section.
60+
/// - identifiers: A list of topic-graph references.
61+
/// - generated: If `true`, this is an automatically generated group. If `false`, this is an authored group.
62+
public init(title: String?, abstract: [RenderInlineContent]?, discussion: RenderSection?, identifierItems: [IdentifierItem], generated: Bool = false) {
63+
self.title = title
64+
self.abstract = abstract
65+
self.discussion = discussion
66+
self.identifierItems = identifierItems
3867
self.generated = generated
3968
}
4069

4170
/// The list of keys you use to encode or decode this section.
4271
private enum CodingKeys: CodingKey {
43-
case title, abstract, discussion, identifiers, generated
72+
case title, abstract, discussion, identifiers, identifierItems, generated
4473
}
4574

4675
public func encode(to encoder: Encoder) throws {
@@ -50,6 +79,7 @@ public struct TaskGroupRenderSection: RenderSection {
5079
try container.encodeIfPresent(abstract, forKey: .abstract)
5180
try container.encodeIfPresent(discussion.map(CodableRenderSection.init), forKey: .discussion)
5281
try container.encode(identifiers, forKey: .identifiers)
82+
try container.encode(identifierItems, forKey: .identifierItems)
5383
if generated {
5484
try container.encode(generated, forKey: .generated)
5585
}
@@ -61,11 +91,18 @@ public struct TaskGroupRenderSection: RenderSection {
6191
title = try container.decodeIfPresent(String.self, forKey: .title)
6292
abstract = try container.decodeIfPresent([RenderInlineContent].self, forKey: .abstract)
6393
discussion = (try container.decodeIfPresent(CodableContentSection.self, forKey: .discussion)).map { $0.section }
64-
identifiers = try container.decode([String].self, forKey: .identifiers)
65-
66-
decoder.registerReferences(identifiers)
67-
94+
95+
let identifiers = try container.decodeIfPresent([String].self, forKey: .identifiers)
96+
let identifierItems = try container.decodeIfPresent([IdentifierItem].self, forKey: .identifierItems)
97+
if let identifierItems = identifierItems {
98+
self.identifierItems = identifierItems
99+
} else if let identifiers = identifiers {
100+
self.identifierItems = identifiers.map { IdentifierItem(identifier: $0) }
101+
} else {
102+
self.identifierItems = []
103+
}
68104
generated = try container.decodeIfPresent(Bool.self, forKey: .generated) ?? false
105+
decoder.registerReferences(self.identifiers)
69106
}
70107
}
71108

@@ -76,7 +113,7 @@ extension TaskGroupRenderSection {
76113
self.title = group.title
77114
self.abstract = nil
78115
self.discussion = nil
79-
self.identifiers = group.references.map({ $0.absoluteString })
116+
self.identifierItems = group.references.map{ IdentifierItem(identifier: $0.absoluteString) }
80117
self.generated = false
81118
}
82119
}

0 commit comments

Comments
 (0)