Create empty markdown files for elements

This commit is contained in:
Christoph Hagen 2022-08-30 20:09:30 +02:00
parent aaa9b0f4aa
commit 20c6d53c6f
2 changed files with 6 additions and 2 deletions

View File

@ -150,9 +150,12 @@ final class FileSystem {
} }
} }
func contentOfOptionalFile(atPath path: String, source: String) -> String? { func contentOfOptionalFile(atPath path: String, source: String, createEmptyFileIfMissing: Bool = false) -> String? {
let url = input.appendingPathComponent(path) let url = input.appendingPathComponent(path)
guard exists(url) else { guard exists(url) else {
if createEmptyFileIfMissing {
try? Data().write(to: url)
}
return nil return nil
} }

View File

@ -59,7 +59,8 @@ struct PageGenerator {
} }
private func makeContent(page: Element, language: String, path: String) -> (content: String, includesCode: Bool)? { private func makeContent(page: Element, language: String, path: String) -> (content: String, includesCode: Bool)? {
guard let content = files.contentOfOptionalFile(atPath: path, source: page.path) else { guard let content = files.contentOfOptionalFile(atPath: path, source: page.path, createEmptyFileIfMissing: true),
content.trimmed != "" else {
return nil return nil
} }
return PageContentGenerator(factory: factory.factory) return PageContentGenerator(factory: factory.factory)