Allow inclusion of html content

This commit is contained in:
Christoph Hagen 2022-09-08 13:12:55 +02:00
parent 3d9551117d
commit 7354d6b58e

View File

@ -79,11 +79,15 @@ struct PageContentGenerator {
// External pages: ![external](url1, text1; url2, text2, ...)
let fileAndTitle = markdown.between("(", and: ")")
let alt = markdown.between("[", and: "]").nonEmpty
if alt == "download" {
switch alt {
case "download":
return handleDownloadButtons(page: page, content: fileAndTitle)
}
if alt == "external" {
case "external":
return handleExternalButtons(page: page, content: fileAndTitle)
case "html":
return handleExternalHTML(page: page, file: fileAndTitle)
default:
break
}
let file = fileAndTitle.dropAfterFirst(" ")
@ -205,4 +209,18 @@ struct PageContentGenerator {
}
return factory.html.externalButtons(buttons)
}
private func handleExternalHTML(page: Element, file: String) -> String {
let url = page.inputFolder.appendingPathComponent(file)
guard url.exists else {
log.add(error: "File \(file) not found", source: page.path)
return ""
}
do {
return try String(contentsOf: url)
} catch {
log.add(error: "File \(file) could not be read", source: page.path, error: error)
return ""
}
}
}