Improve route statistics
This commit is contained in:
@ -33,14 +33,27 @@ struct RouteBlock: KeyedBlockProcessor {
|
||||
}
|
||||
|
||||
func process(_ arguments: [Key : String], markdown: Substring) -> String {
|
||||
let rawComponents = arguments[.components] ?? "all"
|
||||
guard let imageId = arguments[.image],
|
||||
let fileId = arguments[.file],
|
||||
let components = RouteViewComponents(rawValue: rawComponents) else {
|
||||
let fileId = arguments[.file] else {
|
||||
invalid(markdown)
|
||||
return ""
|
||||
}
|
||||
|
||||
let rawComponents = arguments[.components]
|
||||
var displayedTypes: Set<RouteStatisticType> = []
|
||||
if let rawComponents {
|
||||
rawComponents.components(separatedBy: ",").compactMap { $0.trimmed.nonEmpty }.forEach { rawType in
|
||||
if let type = RouteStatisticType(rawValue: rawType) {
|
||||
displayedTypes.insert(type)
|
||||
} else {
|
||||
results.warning("Unknown component type '\(rawType)' in route block")
|
||||
}
|
||||
}
|
||||
}
|
||||
if displayedTypes.isEmpty {
|
||||
displayedTypes = Set(RouteStatisticType.allCases)
|
||||
}
|
||||
|
||||
guard let image = content.image(imageId) else {
|
||||
results.missing(file: imageId, source: "Route block")
|
||||
return ""
|
||||
@ -66,7 +79,7 @@ struct RouteBlock: KeyedBlockProcessor {
|
||||
localization: language == .english ? .english : .german,
|
||||
chartTitle: arguments[.chartTitle],
|
||||
chartId: "chart-" + id,
|
||||
components: components,
|
||||
displayedTypes: displayedTypes,
|
||||
mapTitle: arguments[.mapTitle],
|
||||
mapId: "map-" + id,
|
||||
filePath: file.absoluteUrl,
|
||||
@ -76,6 +89,7 @@ struct RouteBlock: KeyedBlockProcessor {
|
||||
caption: arguments[.caption])
|
||||
|
||||
results.require(footer: views.script)
|
||||
results.require(icons: displayedTypes.map { $0.icon })
|
||||
|
||||
return views.content
|
||||
}
|
||||
|
Reference in New Issue
Block a user