Refactor page content generators
This commit is contained in:
31
CHDataManagement/Generator/Commands/LabelsCommand.swift
Normal file
31
CHDataManagement/Generator/Commands/LabelsCommand.swift
Normal file
@ -0,0 +1,31 @@
|
||||
|
||||
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
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user