Add option to use custom header code

This commit is contained in:
Christoph Hagen 2022-08-16 12:30:50 +02:00
parent c8a70a3d42
commit 5ec0502eab
2 changed files with 18 additions and 2 deletions

View File

@ -20,6 +20,14 @@ extension Page {
let requiredFiles: [String] 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") #warning("Add files for which errors are ignored when missing")
} }
} }
@ -36,7 +44,8 @@ extension Page.Metadata: Metadata {
isDraft: true, isDraft: true,
sortIndex: 0, sortIndex: 0,
languages: [.initial], languages: [.initial],
requiredFiles: []) requiredFiles: [],
useCustomHeader: false)
} }
} }
@ -54,6 +63,7 @@ extension Page.Metadata: Codable {
case sortIndex case sortIndex
case languages case languages
case requiredFiles case requiredFiles
case useCustomHeader
} }
func encode(to encoder: Encoder) throws { func encode(to encoder: Encoder) throws {
@ -71,6 +81,9 @@ extension Page.Metadata: Codable {
if !requiredFiles.isEmpty { if !requiredFiles.isEmpty {
try container.encode(requiredFiles, forKey: .requiredFiles) try container.encode(requiredFiles, forKey: .requiredFiles)
} }
if useCustomHeader {
try container.encode(true, forKey: .useCustomHeader)
}
} }
init(from decoder: Decoder) throws { init(from decoder: Decoder) throws {
@ -89,5 +102,6 @@ extension Page.Metadata: Codable {
self.endDate = nil self.endDate = nil
} }
self.requiredFiles = try container.decodeIfPresent([String].self, forKey: .requiredFiles) ?? [] self.requiredFiles = try container.decodeIfPresent([String].self, forKey: .requiredFiles) ?? []
self.useCustomHeader = try container.decodeIfPresent(Bool.self, forKey: .useCustomHeader) ?? false
} }
} }

View File

@ -35,7 +35,9 @@ struct PageGenerator {
content[.head] = try makeHead(page: page, language: language) content[.head] = try makeHead(page: page, language: language)
content[.topBar] = factory.topBar.generate(section: page.sectionId, languageButton: nextLanguage) content[.topBar] = factory.topBar.generate(section: page.sectionId, languageButton: nextLanguage)
content[.contentClass] = "content" 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[.content] = try makeContent(page: page, language: language, url: inputContentUrl)
content[.previousPageLinkText] = previousPage.unwrapped { factory.makePrevText($0.text) } content[.previousPageLinkText] = previousPage.unwrapped { factory.makePrevText($0.text) }
content[.previousPageUrl] = previousPage?.link content[.previousPageUrl] = previousPage?.link