Add labels block

This commit is contained in:
Christoph Hagen
2025-01-06 17:40:35 +01:00
parent cc19ff4a6f
commit 8e19adda70
5 changed files with 40 additions and 3 deletions

View File

@ -43,6 +43,7 @@ struct ButtonsBlock: BlockLineProcessor {
}
struct ButtonBlock: KeyedBlockProcessor {
enum Key: String, Equatable {
case icon
case file
@ -117,12 +118,11 @@ struct ButtonBlock: KeyedBlockProcessor {
results.externalLink(to: url)
results.require(icon: icon)
return .init(icon: icon, filePath: url, text: text)
return .init(icon: icon, filePath: encodedUrl, text: text)
}
private func action(event: String, icon: PageIcon, text: String) -> ContentButtons.Item? {
results.require(icon: icon)
return .init(icon: icon, filePath: nil, text: text, onClickText: event)
}
}

View File

@ -11,6 +11,8 @@ enum ContentBlock: String, CaseIterable {
case buttons
case labels
var processor: BlockProcessor.Type {
switch self {
case .audio: return AudioBlock.self
@ -18,6 +20,7 @@ enum ContentBlock: String, CaseIterable {
case .video: return VideoBlock.self
case .button: return ButtonBlock.self
case .buttons: return ButtonsBlock.self
case .labels: return LabelsBlock.self
}
}
}

View 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
}
}

View File

@ -18,7 +18,6 @@ import SFSafeSymbols
- Posts: Generate separate pages for posts to link to
- Settings: Introduce `Authors` (`name`, `image`, `description`)
- Page: Property `author`
- Video: Specify versions -> Block
**Generation**
- ImageSet: Specify image aspect ratio (width, height) to prevent page jumps