From 20c6d53c6f5c2e6263d152f706565e49b4011019 Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Tue, 30 Aug 2022 20:09:30 +0200 Subject: [PATCH] Create empty markdown files for elements --- WebsiteGenerator/Files/FileSystem.swift | 5 ++++- WebsiteGenerator/Generators/PageGenerator.swift | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/WebsiteGenerator/Files/FileSystem.swift b/WebsiteGenerator/Files/FileSystem.swift index b730d2d..5706925 100644 --- a/WebsiteGenerator/Files/FileSystem.swift +++ b/WebsiteGenerator/Files/FileSystem.swift @@ -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) guard exists(url) else { + if createEmptyFileIfMissing { + try? Data().write(to: url) + } return nil } diff --git a/WebsiteGenerator/Generators/PageGenerator.swift b/WebsiteGenerator/Generators/PageGenerator.swift index feecc41..8eb3686 100644 --- a/WebsiteGenerator/Generators/PageGenerator.swift +++ b/WebsiteGenerator/Generators/PageGenerator.swift @@ -59,7 +59,8 @@ struct PageGenerator { } 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 PageContentGenerator(factory: factory.factory)