32 lines
944 B
Swift
32 lines
944 B
Swift
|
|
struct LabelsCommand: CommandProcessor {
|
|
|
|
static let commandType: CommandType = .labels
|
|
|
|
let content: Content
|
|
|
|
let results: PageGenerationResults
|
|
|
|
init(content: Content, results: PageGenerationResults, language: ContentLanguage) {
|
|
self.content = content
|
|
self.results = results
|
|
}
|
|
|
|
func process(_ arguments: [String], markdown: Substring) -> String {
|
|
let labels: [ContentLabel] = arguments.compactMap { arg in
|
|
let parts = arg.components(separatedBy: "=")
|
|
guard parts.count == 2 else {
|
|
invalid(markdown)
|
|
return nil
|
|
}
|
|
guard let icon = PageIcon(rawValue: parts[0].trimmed) else {
|
|
invalid(markdown)
|
|
return nil
|
|
}
|
|
results.require(icon: icon)
|
|
return .init(icon: icon, value: parts[1])
|
|
}
|
|
return ContentLabels(labels: labels).content
|
|
}
|
|
}
|