@@ -19,28 +19,57 @@ public struct TaskGroupRenderSection: RenderSection {
19
19
/// An optional discussion for the section.
20
20
public let discussion : RenderSection ?
21
21
/// 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 ]
23
26
/// If true, this is an automatically generated group. If false, this is an authored group.
24
27
public let generated : Bool
25
28
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
+
26
39
/// Creates a new task group.
27
40
/// - Parameters:
28
41
/// - title: An optional title for the section.
29
42
/// - abstract: An optional abstract summary for the section.
30
43
/// - discussion: An optional discussion for the section.
31
44
/// - identifiers: A list of topic-graph references.
32
45
/// - 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. " )
33
47
public init ( title: String ? , abstract: [ RenderInlineContent ] ? , discussion: RenderSection ? , identifiers: [ String ] , generated: Bool = false ) {
34
48
self . title = title
35
49
self . abstract = abstract
36
50
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
38
67
self . generated = generated
39
68
}
40
69
41
70
/// The list of keys you use to encode or decode this section.
42
71
private enum CodingKeys : CodingKey {
43
- case title, abstract, discussion, identifiers, generated
72
+ case title, abstract, discussion, identifiers, identifierItems , generated
44
73
}
45
74
46
75
public func encode( to encoder: Encoder ) throws {
@@ -50,6 +79,7 @@ public struct TaskGroupRenderSection: RenderSection {
50
79
try container. encodeIfPresent ( abstract, forKey: . abstract)
51
80
try container. encodeIfPresent ( discussion. map ( CodableRenderSection . init) , forKey: . discussion)
52
81
try container. encode ( identifiers, forKey: . identifiers)
82
+ try container. encode ( identifierItems, forKey: . identifierItems)
53
83
if generated {
54
84
try container. encode ( generated, forKey: . generated)
55
85
}
@@ -61,11 +91,18 @@ public struct TaskGroupRenderSection: RenderSection {
61
91
title = try container. decodeIfPresent ( String . self, forKey: . title)
62
92
abstract = try container. decodeIfPresent ( [ RenderInlineContent ] . self, forKey: . abstract)
63
93
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
+ }
68
104
generated = try container. decodeIfPresent ( Bool . self, forKey: . generated) ?? false
105
+ decoder. registerReferences ( self . identifiers)
69
106
}
70
107
}
71
108
@@ -76,7 +113,7 @@ extension TaskGroupRenderSection {
76
113
self . title = group. title
77
114
self . abstract = nil
78
115
self . discussion = nil
79
- self . identifiers = group. references. map ( { $0. absoluteString } )
116
+ self . identifierItems = group. references. map { IdentifierItem ( identifier : $0. absoluteString) }
80
117
self . generated = false
81
118
}
82
119
}
0 commit comments