@@ -10,10 +10,10 @@ struct HomePage: Page {
10
10
var enumerations : [ Symbol ] = [ ]
11
11
var structures : [ Symbol ] = [ ]
12
12
var protocols : [ Symbol ] = [ ]
13
- var operatorNames : Set < String > = [ ]
14
- var globalTypealiasNames : Set < String > = [ ]
15
- var globalFunctionNames : Set < String > = [ ]
16
- var globalVariableNames : Set < String > = [ ]
13
+ var operators : [ Symbol ] = [ ]
14
+ var globalTypealias : [ Symbol ] = [ ]
15
+ var globalFunctions : [ Symbol ] = [ ]
16
+ var globalVariables : [ Symbol ] = [ ]
17
17
18
18
init ( module: Module ) {
19
19
self . module = module
@@ -28,16 +28,16 @@ struct HomePage: Page {
28
28
structures. append ( symbol)
29
29
case is Protocol :
30
30
protocols. append ( symbol)
31
- case let `typealias` as Typealias :
32
- globalTypealiasNames . insert ( `typealias` . name )
33
- case let `operator` as Operator :
34
- operatorNames . insert ( `operator` . name )
31
+ case is Typealias :
32
+ globalTypealias . append ( symbol )
33
+ case is Operator :
34
+ operators . append ( symbol )
35
35
case let function as Function where function. isOperator:
36
- operatorNames . insert ( function . name )
37
- case let function as Function :
38
- globalFunctionNames . insert ( function . name )
39
- case let variable as Variable :
40
- globalVariableNames . insert ( variable . name )
36
+ operators . append ( symbol )
37
+ case is Function :
38
+ globalFunctions . append ( symbol )
39
+ case is Variable :
40
+ globalVariables . append ( symbol )
41
41
default :
42
42
continue
43
43
}
@@ -54,6 +54,11 @@ struct HomePage: Page {
54
54
let types = classes + enumerations + structures
55
55
let typeNames = Set ( types. map { $0. id. description } )
56
56
let protocolNames = Set ( protocols. map { $0. id. description } )
57
+ let operatorNames = Set ( operators. map { $0. id. description } )
58
+
59
+ let globalTypealiasNames = Set ( globalTypealias. map { $0. id. description } )
60
+ let globalFunctionNames = Set ( globalFunctions. map { $0. id. description } )
61
+ let globalVariableNames = Set ( globalVariables. map { $0. id. description } )
57
62
58
63
return Document {
59
64
ForEach ( in: [
@@ -107,24 +112,67 @@ struct HomePage: Page {
107
112
return #"""
108
113
<section id= \#( heading. lowercased ( ) ) >
109
114
<h2> \#( heading) </h2>
110
- <dl>
111
- \#( symbols. sorted ( ) . map { symbol -> HypertextLiteral . HTML in
112
- let descriptor = String ( describing: type ( of: symbol. api) ) . lowercased ( )
113
- return #"""
114
- <dt class=" \#( descriptor) ">
115
- <a href= \#( path ( for: symbol) ) title=" \#( descriptor) - \#( symbol. id. description) ">
116
- \#( softbreak ( symbol. id. description) )
117
- </a>
118
- </dt>
119
- <dd>
120
- \#( commonmark: symbol. documentation? . summary ?? " " )
121
- </dd>
122
- """# as HypertextLiteral . HTML
123
- } )
124
- </ dl>
115
+ \#( listHTML ( symbols: symbols) )
125
116
</section>
126
- """ # as HypertextLiteral.HTML
117
+ """#
127
118
} )
119
+ \#( globalsHTML)
120
+ """ #
121
+ }
122
+
123
+ private var globalsHTML: HypertextLiteral.HTML {
124
+ guard !globalTypealias.isEmpty ||
125
+ !globalFunctions.isEmpty ||
126
+ !globalVariables.isEmpty else {
127
+ return " "
128
+ }
129
+
130
+ let heading = " Globals "
131
+ return # """
132
+ < section id= \#( heading. lowercased ( ) ) >
133
+ < h2 > \#( heading) </ h2>
134
+ \#( globalsListHTML)
135
+ </ section>
136
+ """ #
137
+ }
138
+
139
+ private var globalsListHTML: HypertextLiteral.HTML {
140
+ let globals = [
141
+ ( " Typealiases " , globalTypealias),
142
+ ( " Functions " , globalFunctions),
143
+ ( " Variables " , globalVariables),
144
+ ]
145
+ return # """
146
+ \#( globals. compactMap { ( heading, symbols) -> HypertextLiteral . HTML ? in
147
+ guard !symbols. isEmpty else { return nil }
148
+
149
+ return #"""
150
+ <section id= \#( heading. lowercased ( ) ) >
151
+ <h3> \#( heading) </h3>
152
+ \#( listHTML ( symbols: symbols) )
153
+ </section>
154
+ """#
155
+ } )
156
+ """ #
157
+ }
158
+
159
+ private func listHTML(symbols: [Symbol]) -> HypertextLiteral.HTML {
160
+ # """
161
+ < dl>
162
+ \#( symbols. sorted ( ) . map { symbol -> HypertextLiteral . HTML in
163
+ let descriptor = String ( describing: type ( of: symbol. api) ) . lowercased ( )
164
+ return #"""
165
+ <dt class=" \#( descriptor) ">
166
+ <a href= \#( path ( for: symbol) ) title=" \#( descriptor) - \#( symbol. id. description) ">
167
+ \#( softbreak ( symbol. id. description) )
168
+ </a>
169
+ </dt>
170
+ <dd>
171
+ \#( commonmark: symbol. documentation? . summary ?? " " )
172
+ </dd>
173
+ """#
174
+ } )
175
+ </ dl>
128
176
""" #
129
177
}
130
178
}
0 commit comments