Treat placeholder text as markdown

This commit is contained in:
Christoph Hagen 2022-09-02 23:19:30 +02:00
parent d1c418af3e
commit 7f65065f72
2 changed files with 22 additions and 13 deletions

View File

@ -24,9 +24,9 @@ struct PageGenerator {
let inputContentPath = page.path + "/\(language).md"
let metadata = page.localized(for: language)
let nextLanguage = page.nextLanguage(for: language)
let pageContent = makeContent(page: page, language: language, path: inputContentPath)
let pageIncludesCode = pageContent?.includesCode ?? false
let (pageContent, pageIncludesCode, pageIsEmpty) = makeContent(
page: page, metadata: metadata, language: language, path: inputContentPath)
var content = [PageTemplate.Key : String]()
content[.head] = factory.pageHead.generate(page: page, language: language, includesCode: pageIncludesCode)
let sectionUrl = page.sectionUrl(for: language)
@ -36,7 +36,7 @@ struct PageGenerator {
if !page.useCustomHeader {
content[.header] = makeHeader(page: page, metadata: metadata, language: language)
}
content[.content] = pageContent?.content ?? factory.makePlaceholder(metadata: metadata)
content[.content] = pageContent
content[.previousPageLinkText] = previousPage.unwrapped { factory.factory.html.makePrevText($0.text) }
content[.previousPageUrl] = previousPage?.link
content[.nextPageLinkText] = nextPage.unwrapped { factory.factory.html.makeNextText($0.text) }
@ -51,7 +51,7 @@ struct PageGenerator {
let url = files.urlInOutputFolder(path)
if page.state == .draft {
files.isDraft(path: page.path)
} else if pageContent == nil, page.state != .hidden {
} else if pageIsEmpty, page.state != .hidden {
files.isEmpty(page: path)
}
guard factory.page.generate(content, to: url) else {
@ -60,13 +60,18 @@ struct PageGenerator {
files.generated(page: path)
}
private func makeContent(page: Element, language: String, path: String) -> (content: String, includesCode: Bool)? {
guard let content = files.contentOfOptionalFile(atPath: path, source: page.path, createEmptyFileIfMissing: true),
content.trimmed != "" else {
return nil
private func makeContent(page: Element, metadata: Element.LocalizedMetadata, language: String, path: String) -> (content: String, includesCode: Bool, isEmpty: Bool) {
if let raw = files.contentOfOptionalFile(atPath: path, source: page.path, createEmptyFileIfMissing: true)?
.trimmed.nonEmpty {
let (content, includesCode) = PageContentGenerator(factory: factory.factory)
.generate(page: page, language: language, content: raw)
return (content, includesCode, false)
} 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)
return (placeholder, includesCode, true)
}
return PageContentGenerator(factory: factory.factory)
.generate(page: page, language: language, content: content)
}
private func makeHeader(page: Element, metadata: Element.LocalizedMetadata, language: String) -> String {

View File

@ -75,9 +75,13 @@ 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: metadata.placeholderTitle,
.text: metadata.placeholderText])
.title: title,
.text: text])
}
func makeBackLink(text: String, language: String) -> String {