diff --git a/Sources/Generator/Generators/MarkdownProcessor.swift b/Sources/Generator/Generators/MarkdownProcessor.swift index 58cd0b3..e30fb03 100644 --- a/Sources/Generator/Generators/MarkdownProcessor.swift +++ b/Sources/Generator/Generators/MarkdownProcessor.swift @@ -76,6 +76,7 @@ struct PageContentGenerator { // For videos: ![option1,option2,...](file) // For svg with custom area: ![x,y,width,height](file.svg) // For downloads: ![download](file1, text1; file2, text2, ...) + // For a simple boxes: ![box](title;body) // External pages: ![external](url1, text1; url2, text2, ...) let fileAndTitle = markdown.between("(", and: ")") let alt = markdown.between("[", and: "]").nonEmpty @@ -86,6 +87,8 @@ struct PageContentGenerator { return handleExternalButtons(page: page, content: fileAndTitle) case "html": return handleExternalHTML(page: page, file: fileAndTitle) + case "box": + return handleSimpleBox(page: page, content: fileAndTitle) default: break } @@ -231,4 +234,15 @@ struct PageContentGenerator { return "" } } + + private func handleSimpleBox(page: Element, content: String) -> String { + let parts = content.components(separatedBy: ";") + guard parts.count > 1 else { + log.add(error: "Invalid box specification", source: page.path) + return "" + } + let title = parts[0] + let text = parts.dropFirst().joined(separator: ";") + return factory.makePlaceholder(title: title, text: text) + } } diff --git a/Sources/Generator/Generators/PageGenerator.swift b/Sources/Generator/Generators/PageGenerator.swift index 39928b6..d935e3c 100644 --- a/Sources/Generator/Generators/PageGenerator.swift +++ b/Sources/Generator/Generators/PageGenerator.swift @@ -68,7 +68,7 @@ struct PageGenerator { } else { let (content, includesCode) = PageContentGenerator(factory: factory.factory) .generate(page: page, language: language, content: metadata.placeholderText) - let placeholder = factory.makePlaceholder(title: metadata.placeholderTitle, text: content) + let placeholder = factory.factory.makePlaceholder(title: metadata.placeholderTitle, text: content) return (placeholder, includesCode, true) } } diff --git a/Sources/Generator/Templates/Elements/PlaceholderTemplate.swift b/Sources/Generator/Templates/Elements/BoxTemplate.swift similarity index 63% rename from Sources/Generator/Templates/Elements/PlaceholderTemplate.swift rename to Sources/Generator/Templates/Elements/BoxTemplate.swift index 1e1cd5d..c2de89e 100644 --- a/Sources/Generator/Templates/Elements/PlaceholderTemplate.swift +++ b/Sources/Generator/Templates/Elements/BoxTemplate.swift @@ -1,13 +1,13 @@ import Foundation -struct PlaceholderTemplate: Template { +struct BoxTemplate: Template { enum Key: String, CaseIterable { case title = "TITLE" case text = "TEXT" } - static let templateName = "empty.html" + static let templateName = "box.html" var raw: String } diff --git a/Sources/Generator/Templates/Filled/LocalizedSiteTemplate.swift b/Sources/Generator/Templates/Filled/LocalizedSiteTemplate.swift index 559e45d..4c90a82 100644 --- a/Sources/Generator/Templates/Filled/LocalizedSiteTemplate.swift +++ b/Sources/Generator/Templates/Filled/LocalizedSiteTemplate.swift @@ -75,13 +75,7 @@ struct LocalizedSiteTemplate { // MARK: Content func makePlaceholder(metadata: Element.LocalizedMetadata) -> String { - makePlaceholder(title: metadata.placeholderTitle, text: metadata.placeholderText) - } - - func makePlaceholder(title: String, text: String) -> String { - factory.placeholder.generate([ - .title: title, - .text: text]) + factory.makePlaceholder(title: metadata.placeholderTitle, text: metadata.placeholderText) } func makeBackLink(text: String, language: String) -> String { diff --git a/Sources/Generator/Templates/TemplateFactory.swift b/Sources/Generator/Templates/TemplateFactory.swift index cbb0e73..5839d99 100644 --- a/Sources/Generator/Templates/TemplateFactory.swift +++ b/Sources/Generator/Templates/TemplateFactory.swift @@ -16,7 +16,7 @@ final class TemplateFactory { let overviewSectionClean: OverviewSectionCleanTemplate - let placeholder: PlaceholderTemplate + let box: BoxTemplate // MARK: Thumbnails @@ -64,7 +64,7 @@ final class TemplateFactory { self.topBar = try .init(in: templateFolder) self.overviewSection = try .init(in: templateFolder) self.overviewSectionClean = try .init(in: templateFolder) - self.placeholder = try .init(in: templateFolder) + self.box = try .init(in: templateFolder) self.largeThumbnail = try .init(in: templateFolder) self.squareThumbnail = try .init(in: templateFolder) self.smallThumbnail = try .init(in: templateFolder) @@ -75,4 +75,12 @@ final class TemplateFactory { self.video = try .init(in: templateFolder) self.html = .init() } + + // MARK: Convenience methods + + func makePlaceholder(title: String, text: String) -> String { + box.generate([ + .title: title, + .text: text]) + } }