Reorganize headers, page templates

This commit is contained in:
Christoph Hagen 2022-08-16 12:27:13 +02:00
parent 02a3dd4007
commit c8a70a3d42
10 changed files with 111 additions and 62 deletions

View File

@ -36,13 +36,13 @@
E22E87B2289F296700E51191 /* ThumbnailInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = E22E87B1289F296700E51191 /* ThumbnailInfo.swift */; };
E22E87B6289FF67B00E51191 /* Metadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = E22E87B5289FF67B00E51191 /* Metadata.swift */; };
E26555E428A2C4FA00BAF496 /* LinkPreviewMetadataProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = E26555E328A2C4FA00BAF496 /* LinkPreviewMetadataProvider.swift */; };
E2C5A5D528A0223C00102A25 /* OverviewPageTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2C5A5D428A0223C00102A25 /* OverviewPageTemplate.swift */; };
E2C5A5D528A0223C00102A25 /* HeaderTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2C5A5D428A0223C00102A25 /* HeaderTemplate.swift */; };
E2C5A5D728A022C500102A25 /* TemplateFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2C5A5D628A022C500102A25 /* TemplateFactory.swift */; };
E2C5A5D928A023FA00102A25 /* PageHeadTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2C5A5D828A023FA00102A25 /* PageHeadTemplate.swift */; };
E2C5A5DB28A02F9000102A25 /* TopBarTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2C5A5DA28A02F9000102A25 /* TopBarTemplate.swift */; };
E2C5A5DD28A036BE00102A25 /* OverviewSectionTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2C5A5DC28A036BE00102A25 /* OverviewSectionTemplate.swift */; };
E2C5A5E128A0373300102A25 /* ThumbnailTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2C5A5E028A0373300102A25 /* ThumbnailTemplate.swift */; };
E2C5A5E328A037F900102A25 /* ContentPageTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2C5A5E228A037F900102A25 /* ContentPageTemplate.swift */; };
E2C5A5E328A037F900102A25 /* PageTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2C5A5E228A037F900102A25 /* PageTemplate.swift */; };
E2C5A5E528A03A6500102A25 /* BackNavigationTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2C5A5E428A03A6500102A25 /* BackNavigationTemplate.swift */; };
E2C5A5E928A0451C00102A25 /* LocalizedSiteTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2C5A5E828A0451C00102A25 /* LocalizedSiteTemplate.swift */; };
E2C5A5EC28A055E900102A25 /* SiteElement.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2C5A5EB28A055E900102A25 /* SiteElement.swift */; };
@ -95,13 +95,13 @@
E22E87B1289F296700E51191 /* ThumbnailInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThumbnailInfo.swift; sourceTree = "<group>"; };
E22E87B5289FF67B00E51191 /* Metadata.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Metadata.swift; sourceTree = "<group>"; };
E26555E328A2C4FA00BAF496 /* LinkPreviewMetadataProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkPreviewMetadataProvider.swift; sourceTree = "<group>"; };
E2C5A5D428A0223C00102A25 /* OverviewPageTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OverviewPageTemplate.swift; sourceTree = "<group>"; };
E2C5A5D428A0223C00102A25 /* HeaderTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeaderTemplate.swift; sourceTree = "<group>"; };
E2C5A5D628A022C500102A25 /* TemplateFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TemplateFactory.swift; sourceTree = "<group>"; };
E2C5A5D828A023FA00102A25 /* PageHeadTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageHeadTemplate.swift; sourceTree = "<group>"; };
E2C5A5DA28A02F9000102A25 /* TopBarTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopBarTemplate.swift; sourceTree = "<group>"; };
E2C5A5DC28A036BE00102A25 /* OverviewSectionTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OverviewSectionTemplate.swift; sourceTree = "<group>"; };
E2C5A5E028A0373300102A25 /* ThumbnailTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThumbnailTemplate.swift; sourceTree = "<group>"; };
E2C5A5E228A037F900102A25 /* ContentPageTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentPageTemplate.swift; sourceTree = "<group>"; };
E2C5A5E228A037F900102A25 /* PageTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageTemplate.swift; sourceTree = "<group>"; };
E2C5A5E428A03A6500102A25 /* BackNavigationTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackNavigationTemplate.swift; sourceTree = "<group>"; };
E2C5A5E828A0451C00102A25 /* LocalizedSiteTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalizedSiteTemplate.swift; sourceTree = "<group>"; };
E2C5A5EB28A055E900102A25 /* SiteElement.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SiteElement.swift; sourceTree = "<group>"; };
@ -231,8 +231,8 @@
E2C5A5E728A03E4000102A25 /* Pages */ = {
isa = PBXGroup;
children = (
E2C5A5D428A0223C00102A25 /* OverviewPageTemplate.swift */,
E2C5A5E228A037F900102A25 /* ContentPageTemplate.swift */,
E2C5A5D428A0223C00102A25 /* HeaderTemplate.swift */,
E2C5A5E228A037F900102A25 /* PageTemplate.swift */,
);
path = Pages;
sourceTree = "<group>";
@ -313,7 +313,7 @@
E2C5A5D728A022C500102A25 /* TemplateFactory.swift in Sources */,
E22E8772289D8C2700E51191 /* IndexPageGenerator.swift in Sources */,
E22E876E289D868100E51191 /* Site+LocalizedMetadata.swift in Sources */,
E2C5A5D528A0223C00102A25 /* OverviewPageTemplate.swift in Sources */,
E2C5A5D528A0223C00102A25 /* HeaderTemplate.swift in Sources */,
E22E876C289D855D00E51191 /* ThumbnailStyle.swift in Sources */,
E22E8798289EA42C00E51191 /* FileProcessor.swift in Sources */,
E26555E428A2C4FA00BAF496 /* LinkPreviewMetadataProvider.swift in Sources */,
@ -337,7 +337,7 @@
E2C5A5EC28A055E900102A25 /* SiteElement.swift in Sources */,
E22E87B0289F221A00E51191 /* PrefilledTopBarTemplate.swift in Sources */,
E22E87A8289F0E7B00E51191 /* PageGenerator.swift in Sources */,
E2C5A5E328A037F900102A25 /* ContentPageTemplate.swift in Sources */,
E2C5A5E328A037F900102A25 /* PageTemplate.swift in Sources */,
E2C5A5DD28A036BE00102A25 /* OverviewSectionTemplate.swift in Sources */,
E2C5A5E528A03A6500102A25 /* BackNavigationTemplate.swift in Sources */,
E2C5A5DB28A02F9000102A25 /* TopBarTemplate.swift in Sources */,

View File

@ -0,0 +1,14 @@
{
"pins" : [
{
"identity" : "ink",
"kind" : "remoteSourceControl",
"location" : "https://github.com/johnsundell/ink.git",
"state" : {
"revision" : "77c3d8953374a9cf5418ef0bd7108524999de85a",
"version" : "0.5.1"
}
}
],
"version" : 2
}

View File

@ -32,20 +32,19 @@ struct IndexPageGenerator {
to url: URL) throws {
let localized = site.localized(for: language)
var content = [OverviewPageTemplate.Key : String]()
var content = [PageTemplate.Key : String]()
content[.head] = try makeHead(site: site, language: language)
content[.topBar] = factory.topBar.generate(section: nil, languageButton: languageButton)
content[.title] = localized.title
content[.subtitle] = localized.subtitle
content[.titleText] = localized.description
content[.contentClass] = "overview"
content[.header] = makeHeader(localized: localized)
let sections = site.elements.compactMap { $0 as? Section }
content[.sections] = try factory.overviewSection.generate(
content[.content] = try factory.overviewSection.generate(
sections: sections,
in: site,
language: language,
sectionItemCount: sectionItemCount)
content[.footer] = SiteGenerator.pageFooter
try factory.overviewPage.generate(content, to: url)
try factory.page.generate(content, to: url)
}
private func makeHead(site: Site, language: String) throws -> String {
@ -57,4 +56,12 @@ struct IndexPageGenerator {
linkPreviewImage: site.linkPreviewImage(for: language),
customHeadContent: try site.customHeadContent()))
}
private func makeHeader(localized: Site.LocalizedMetadata) -> String {
var content = [HeaderKey : String]()
content[.title] = localized.title
content[.subtitle] = localized.subtitle
content[.titleText] = localized.description
return factory.factory.centeredHeader.generate(content)
}
}

View File

@ -19,19 +19,17 @@ struct OverviewPageGenerator {
let metadata = section.localized(for: language)
var content = [OverviewPageTemplate.Key : String]()
var content = [PageTemplate.Key : String]()
content[.head] = try makeHead(section: section, language: language)
let languageButton = section.nextLanguage(for: language)
content[.topBar] = factory.topBar.generate(
section: section.sectionId,
languageButton: languageButton)
content[.sections] = try makeContent(section: section, language: language)
content[.title] = metadata.title
content[.subtitle] = metadata.subtitle
content[.titleText] = metadata.description
content[.contentClass] = "overview"
content[.header] = makeHeader(metadata: metadata, language: language, backText: backText)
content[.content] = try makeContent(section: section, language: language)
content[.footer] = SiteGenerator.pageFooter
content[.backLink] = backText.unwrapped { factory.makeBackLink(text: $0, language: language) }
try factory.overviewPage.generate(content, to: url)
try factory.page.generate(content, to: url)
}
private func makeContent(section: Section, language: String) throws -> String {
@ -59,4 +57,15 @@ struct OverviewPageGenerator {
customHeadContent: try section.customHeadContent())
return try factory.pageHead.generate(page: info)
}
private func makeHeader(metadata: Section.LocalizedMetadata,
language: String,
backText: String?) -> String {
var content = [HeaderKey : String]()
content[.title] = metadata.title
content[.subtitle] = metadata.subtitle
content[.titleText] = metadata.description
content[.backLink] = backText.unwrapped { factory.makeBackLink(text: $0, language: language) }
return factory.factory.centeredHeader.generate(content)
}
}

View File

@ -31,13 +31,11 @@ struct PageGenerator {
#warning("Make prev and next navigation relative")
let metadata = page.localized(for: language)
let nextLanguage = page.nextLanguage(for: language)
var content = [ContentPageTemplate.Key : String]()
var content = [PageTemplate.Key : String]()
content[.head] = try makeHead(page: page, language: language)
content[.topBar] = factory.topBar.generate(section: page.sectionId, languageButton: nextLanguage)
content[.backLink] = factory.makeBackLink(text: backText, language: language)
content[.title] = metadata.title
content[.subtitle] = metadata.subtitle
content[.date] = factory.makeDateString(start: page.metadata.date, end: page.metadata.endDate)
content[.contentClass] = "content"
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
@ -45,8 +43,8 @@ struct PageGenerator {
content[.nextPageUrl] = nextPage?.link
content[.footer] = try page.customFooterContent()
try factory.contentPage.generate(content, to: url)
let url = files.outputFolder.appendingPathComponent(path)
try factory.page.generate(content, to: url)
}
private func makeContent(page: Page, language: String, url: URL) throws -> String {
@ -68,4 +66,13 @@ struct PageGenerator {
customHeadContent: try page.customHeadContent())
return try factory.pageHead.generate(page: info)
}
private func makeHeader(page: Page.Metadata, metadata: Page.LocalizedMetadata, language: String, backText: String) -> String {
var content = [HeaderKey : String]()
content[.backLink] = factory.makeBackLink(text: backText, language: language)
content[.title] = metadata.title
content[.subtitle] = metadata.subtitle
content[.date] = factory.makeDateString(start: page.date, end: page.endDate)
return factory.factory.leftHeader.generate(content)
}
}

View File

@ -46,12 +46,8 @@ struct LocalizedSiteTemplate {
// MARK: Pages
var overviewPage: OverviewPageTemplate {
factory.overviewPage
}
var contentPage: ContentPageTemplate {
factory.contentPage
var page: PageTemplate {
factory.page
}
init(factory: TemplateFactory, language: String, site: Site, files: FileProcessor) throws {

View File

@ -0,0 +1,32 @@
import Foundation
protocol HeaderTemplate {
func generate(_ content: [ThumbnailKey : String], shouldIndent: Bool) throws -> String
}
enum HeaderKey: String, CaseIterable {
case backLink = "BACK_LINK"
case title = "TITLE"
case subtitle = "SUBTITLE"
case titleText = "TITLE_TEXT"
case date = "DATE"
}
struct CenteredHeaderTemplate: Template {
typealias Key = HeaderKey
let raw: String
static let templateName = "header-center.html"
}
struct LeftHeaderTemplate: Template {
typealias Key = HeaderKey
let raw: String
static let templateName = "header-left.html"
}

View File

@ -1,19 +0,0 @@
import Foundation
struct OverviewPageTemplate: Template {
enum Key: String, CaseIterable {
case head = "HEAD"
case topBar = "TOP_BAR"
case backLink = "BACK_LINK"
case title = "TITLE"
case subtitle = "SUBTITLE"
case titleText = "TITLE_TEXT"
case sections = "SECTIONS"
case footer = "FOOTER"
}
let raw: String
static let templateName = "overview-page.html"
}

View File

@ -1,14 +1,12 @@
import Foundation
struct ContentPageTemplate: Template {
struct PageTemplate: Template {
enum Key: String, CaseIterable {
case head = "HEAD"
case topBar = "TOP_BAR"
case backLink = "BACK_LINK"
case title = "TITLE"
case subtitle = "SUBTITLE"
case date = "DATE"
case contentClass = "CONTENT_CLASS"
case header = "HEADER"
case content = "CONTENT"
case previousPageLinkText = "PREV_TEXT"
case previousPageUrl = "PREV_LINK"

View File

@ -37,11 +37,15 @@ final class TemplateFactory {
}
}
// MARK: Headers
let leftHeader: LeftHeaderTemplate
let centeredHeader: CenteredHeaderTemplate
// MARK: Pages
let overviewPage: OverviewPageTemplate
let contentPage: ContentPageTemplate
let page: PageTemplate
// MARK: Init
@ -56,7 +60,8 @@ final class TemplateFactory {
self.largeThumbnail = try .init(in: templateFolder)
self.squareThumbnail = try .init(in: templateFolder)
self.smallThumbnail = try .init(in: templateFolder)
self.overviewPage = try .init(in: templateFolder)
self.contentPage = try .init(in: templateFolder)
self.leftHeader = try .init(in: templateFolder)
self.centeredHeader = try .init(in: templateFolder)
self.page = try .init(in: templateFolder)
}
}