Skip to content

Commit 7252498

Browse files
committed
add help article about mangled names
1 parent 2cf833b commit 7252498

File tree

16 files changed

+168
-13
lines changed

16 files changed

+168
-13
lines changed

Sources/Swiftinit/Swiftinit.Root.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ extension Swiftinit
1111
case blog
1212
case docs
1313
case docc
14+
case help
1415
case hist
1516
case login
1617
case lunr
@@ -53,6 +54,7 @@ extension Swiftinit.Root:Identifiable
5354
case .blog: "articles"
5455
case .docs: "docs"
5556
case .docc: "docc"
57+
case .help: "help"
5658
case .hist: "hist"
5759
case .login: "login"
5860
case .lunr: "lunr"

Sources/SwiftinitPages/Surfaces/Vertices/Swiftinit.Blog.Article.swift renamed to Sources/SwiftinitPages/Surfaces/Vertices/Swiftinit.Blog.ArticlePage.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ extension Swiftinit.Blog.ArticlePage
2828
}
2929
extension Swiftinit.Blog.ArticlePage:Swiftinit.RenderablePage
3030
{
31-
var title:String { "\(self.volume.title) Documentation" }
31+
var title:String { "\(self.vertex.headline.safe)" }
32+
33+
var description:String?
34+
{
35+
self.vertex.overview.map { "\(self.context.prose($0.markdown))" }
36+
}
3237
}
3338
extension Swiftinit.Blog.ArticlePage:Swiftinit.StaticPage
3439
{

Sources/SwiftinitPages/Surfaces/Vertices/Swiftinit.Docs.DeclPage.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,14 @@ extension Swiftinit.Docs.DeclPage:Swiftinit.VertexPage
221221
$0[.p, { $0.class = "symbol" }]
222222
{
223223
$0[.code] = self.vertex.symbol.rawValue
224+
225+
$0[.span, { $0.class = "parenthetical" }]
226+
{
227+
$0[.a]
228+
{
229+
$0.href = "/help/what-are-mangled-names"
230+
} = "What are these?"
231+
}
224232
}
225233

226234
$0[.p]

Sources/SwiftinitServer/Server/Swiftinit.ClientAnnotation.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import HTTP
2+
import HTTPServer
23
import IP
34
import UA
45
import UnidocProfiling
@@ -71,11 +72,7 @@ extension Swiftinit.ClientAnnotation
7172
}
7273

7374
if case "*"? = headers.acceptLanguage,
74-
agent == """
75-
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) \
76-
AppleWebKit/605.1.15 (KHTML, like Gecko) \
77-
Version/14.0 Safari/605.1.15
78-
"""
75+
agent.starts(with: "Discourse Forum Onebox")
7976
{
8077
// This is *probably* the Swift Forums bot.
8178
return .robot(.discoursebot)

Sources/SwiftinitServer/Swiftinit.AnyEndpoint.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,13 @@ extension Swiftinit.AnyEndpoint
145145
}
146146

147147
static
148-
func get(articles trunk:String,
148+
func get(blog:String,
149+
_ trunk:String,
149150
with parameters:Swiftinit.PipelineParameters) -> Self
150151
{
151152
.explainable(Swiftinit.BlogEndpoint.init(query: .init(
152153
volume: .init(package: "__swiftinit", version: "__max"),
153-
vertex: .init(path: ["Articles", trunk], hash: nil))),
154+
vertex: .init(path: [blog, trunk], hash: nil))),
154155
parameters: parameters)
155156
}
156157

Sources/SwiftinitServer/Swiftinit.IntegralRequest.Metadata.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import HTTP
2+
import HTTPServer
23
import IP
34
import NIOHPACK
45
import NIOHTTP1
@@ -19,6 +20,7 @@ extension Swiftinit.IntegralRequest
1920
let service:IP.Service?
2021
let path:String
2122

23+
private
2224
init(
2325
annotation:Swiftinit.ClientAnnotation,
2426
cookies:Swiftinit.Cookies,
@@ -97,5 +99,14 @@ extension Swiftinit.IntegralRequest.Metadata
9799
address: address,
98100
service: service,
99101
path: path)
102+
103+
if case .robot(.discoursebot) = self.annotation
104+
{
105+
Log[.debug] = """
106+
Approved possible Swift Forums robot
107+
User-Agent: '\(headers.userAgent ?? "")'
108+
IP Address: \(address)
109+
"""
110+
}
100111
}
101112
}

Sources/SwiftinitServer/Swiftinit.IntegralRequest.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,17 @@ extension Swiftinit.IntegralRequest
198198
with: .init(uri.query?.parameters))
199199

200200
case Swiftinit.Root.blog.id:
201-
endpoint = .get(articles: trunk,
201+
endpoint = .get(blog: "Articles", trunk,
202202
with: .init(uri.query?.parameters, tag: tag))
203203

204204
case Swiftinit.Root.docs.id, Swiftinit.Root.docc.id, Swiftinit.Root.hist.id:
205205
endpoint = .get(docs: trunk, path,
206206
with: .init(uri.query?.parameters, tag: tag))
207207

208+
case Swiftinit.Root.help.id:
209+
endpoint = .get(blog: "Help", trunk,
210+
with: .init(uri.query?.parameters, tag: tag))
211+
208212
case Swiftinit.Root.lunr.id:
209213
endpoint = .get(lunr: trunk,
210214
with: .init(uri.query?.parameters, tag: tag))

Sources/UnidocLinker/Resolver/Unidoc.Resolver.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,11 @@ extension Unidoc.Resolver
189189
return .text(unresolved.link)
190190
}
191191

192-
let text:String = codelink.path.visible.joined(separator: ".")
192+
/// This looks a lot like a stem, but it always uses spaces, never tabs.
193+
/// Its purpose is to allow splitting the path into words without parsing the
194+
/// Swift language grammar.
195+
var path:String { codelink.path.visible.joined(separator: " ") }
196+
var text:String { codelink.path.visible.joined(separator: ".") }
193197
let length:Int = codelink.path.visible.count
194198

195199
switch resolution
@@ -198,10 +202,10 @@ extension Unidoc.Resolver
198202
return .text(text)
199203

200204
case .scalar(let scalar)?:
201-
return .path(text, self.context.expand(scalar, to: length))
205+
return .path(path, self.context.expand(scalar, to: length))
202206

203207
case .vector(let feature, self: let heir)?:
204-
return .path(text, self.context.expand((heir, feature), to: length))
208+
return .path(path, self.context.expand((heir, feature), to: length))
205209
}
206210
}
207211

TestPackages/__swiftinit/Package.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ let package:Package = .init(name: "Swiftinit",
55
products:
66
[
77
.library(name: "Articles", targets: ["Articles"]),
8+
.library(name: "Help", targets: ["Help"]),
89
],
910
targets:
1011
[
11-
.target(name: "Articles", exclude: ["md"]),
12+
.target(name: "Articles"),
13+
.target(name: "Help"),
1214
])

0 commit comments

Comments
 (0)