Add labels block
This commit is contained in:
31
CHDataManagement/Generator/Blocks/LabelsBlock.swift
Normal file
31
CHDataManagement/Generator/Blocks/LabelsBlock.swift
Normal file
@ -0,0 +1,31 @@
|
||||
|
||||
struct LabelsBlock: OrderedKeyBlockProcessor {
|
||||
|
||||
typealias Key = PageIcon
|
||||
|
||||
static let blockId: ContentBlock = .labels
|
||||
|
||||
let content: Content
|
||||
|
||||
let results: PageGenerationResults
|
||||
|
||||
let language: ContentLanguage
|
||||
|
||||
init(content: Content, results: PageGenerationResults, language: ContentLanguage) {
|
||||
self.content = content
|
||||
self.results = results
|
||||
self.language = language
|
||||
}
|
||||
|
||||
func process(_ arguments: [(key: PageIcon, value: String)], markdown: Substring) -> String {
|
||||
let labels: [ContentLabel] = arguments.compactMap { (icon, value) in
|
||||
guard value != "" else {
|
||||
invalid(markdown)
|
||||
return nil
|
||||
}
|
||||
results.require(icon: icon)
|
||||
return .init(icon: icon, value: value)
|
||||
}
|
||||
return ContentLabels(labels: labels).content
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user