From 5ec0502eabbc1abb630400285e67a4a452c772b9 Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Tue, 16 Aug 2022 12:30:50 +0200 Subject: [PATCH] Add option to use custom header code --- WebsiteGenerator/Content/Page+Metadata.swift | 16 +++++++++++++++- WebsiteGenerator/Generators/PageGenerator.swift | 4 +++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/WebsiteGenerator/Content/Page+Metadata.swift b/WebsiteGenerator/Content/Page+Metadata.swift index 9f90a50..073e821 100644 --- a/WebsiteGenerator/Content/Page+Metadata.swift +++ b/WebsiteGenerator/Content/Page+Metadata.swift @@ -20,6 +20,14 @@ extension Page { let requiredFiles: [String] + /** + Indicate that no header should be generated automatically. + + This option assumes that custom header code is present in the page source files + - Note: If not specified, this property defaults to `false`. + */ + let useCustomHeader: Bool + #warning("Add files for which errors are ignored when missing") } } @@ -36,7 +44,8 @@ extension Page.Metadata: Metadata { isDraft: true, sortIndex: 0, languages: [.initial], - requiredFiles: []) + requiredFiles: [], + useCustomHeader: false) } } @@ -54,6 +63,7 @@ extension Page.Metadata: Codable { case sortIndex case languages case requiredFiles + case useCustomHeader } func encode(to encoder: Encoder) throws { @@ -71,6 +81,9 @@ extension Page.Metadata: Codable { if !requiredFiles.isEmpty { try container.encode(requiredFiles, forKey: .requiredFiles) } + if useCustomHeader { + try container.encode(true, forKey: .useCustomHeader) + } } init(from decoder: Decoder) throws { @@ -89,5 +102,6 @@ extension Page.Metadata: Codable { self.endDate = nil } self.requiredFiles = try container.decodeIfPresent([String].self, forKey: .requiredFiles) ?? [] + self.useCustomHeader = try container.decodeIfPresent(Bool.self, forKey: .useCustomHeader) ?? false } } diff --git a/WebsiteGenerator/Generators/PageGenerator.swift b/WebsiteGenerator/Generators/PageGenerator.swift index c8a5345..dd7e89f 100644 --- a/WebsiteGenerator/Generators/PageGenerator.swift +++ b/WebsiteGenerator/Generators/PageGenerator.swift @@ -35,7 +35,9 @@ struct PageGenerator { content[.head] = try makeHead(page: page, language: language) content[.topBar] = factory.topBar.generate(section: page.sectionId, languageButton: nextLanguage) content[.contentClass] = "content" - content[.header] = makeHeader(page: page.metadata, metadata: metadata, language: language, backText: backText) + if page.metadata.useCustomHeader { + content[.header] = makeHeader(page: page.metadata, metadata: metadata, language: language, backText: backText) + } content[.content] = try makeContent(page: page, language: language, url: inputContentUrl) content[.previousPageLinkText] = previousPage.unwrapped { factory.makePrevText($0.text) } content[.previousPageUrl] = previousPage?.link