diff --git a/WebsiteGenerator/Generators/HTMLElementsGenerator.swift b/WebsiteGenerator/Generators/HTMLElementsGenerator.swift index 4d63076..91b1b08 100644 --- a/WebsiteGenerator/Generators/HTMLElementsGenerator.swift +++ b/WebsiteGenerator/Generators/HTMLElementsGenerator.swift @@ -62,6 +62,13 @@ struct HTMLElementsGenerator { return flexParagraph(content) } + func externalButtons(_ buttons: [(url: String, text: String)]) -> String { + let content = buttons + .map { externalLink(url: $0.url, text: $0.text) } + .joined(separator: "\n") + return flexParagraph(content) + } + private func flexParagraph(_ content: String) -> String { """

@@ -73,7 +80,7 @@ struct HTMLElementsGenerator { private func button(file: String, text: String) -> String { """ - \(text) + \(text) """ } @@ -81,9 +88,16 @@ struct HTMLElementsGenerator { private func button(file: String, text: String, downloadName: String) -> String { """ - \(text) + \(text) + """ + } + private func externalLink(url: String, text: String) -> String { + """ + + \(text) + """ } diff --git a/WebsiteGenerator/Generators/MarkdownProcessor.swift b/WebsiteGenerator/Generators/MarkdownProcessor.swift index d21688a..ac7fd89 100644 --- a/WebsiteGenerator/Generators/MarkdownProcessor.swift +++ b/WebsiteGenerator/Generators/MarkdownProcessor.swift @@ -60,6 +60,9 @@ struct PageContentGenerator { if alt == "download" { return handleDownloadButtons(page: page, content: fileAndTitle) } + if alt == "external" { + return handleExternalButtons(page: page, content: fileAndTitle) + } let file = fileAndTitle.dropAfterFirst(" ") let title = fileAndTitle.contains(" ") ? fileAndTitle.dropBeforeFirst(" ").nonEmpty : nil @@ -163,4 +166,21 @@ struct PageContentGenerator { } return factory.html.downloadButtons(buttons) } + + private func handleExternalButtons(page: Element, content: String) -> String { + let buttons = content + .components(separatedBy: ";") + .compactMap { button -> (url: String, text: String)? in + let parts = button.components(separatedBy: ",") + guard parts.count == 2 else { + log.add(warning: "Invalid external link definition", source: page.path) + return nil + } + let url = parts[0].trimmed + let title = parts[1].trimmed + + return (url, title) + } + return factory.html.externalButtons(buttons) + } }