Add title suffix, extract HTML elements
Fix header calls
This commit is contained in:
parent
9c74f76650
commit
4036452d2c
@ -28,6 +28,7 @@
|
||||
E253C87F28B8FBB00076B6D0 /* Data+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E253C87E28B8FBB00076B6D0 /* Data+Extensions.swift */; };
|
||||
E253C88128B8FBFF0076B6D0 /* NSSize+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E253C88028B8FBFF0076B6D0 /* NSSize+Extensions.swift */; };
|
||||
E253C88328B8FC470076B6D0 /* NSImage+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E253C88228B8FC470076B6D0 /* NSImage+Extensions.swift */; };
|
||||
E253C88528BA32FB0076B6D0 /* HTMLElementsGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = E253C88428BA32FB0076B6D0 /* HTMLElementsGenerator.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 */; };
|
||||
@ -88,6 +89,7 @@
|
||||
E253C87E28B8FBB00076B6D0 /* Data+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+Extensions.swift"; sourceTree = "<group>"; };
|
||||
E253C88028B8FBFF0076B6D0 /* NSSize+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSSize+Extensions.swift"; sourceTree = "<group>"; };
|
||||
E253C88228B8FC470076B6D0 /* NSImage+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSImage+Extensions.swift"; sourceTree = "<group>"; };
|
||||
E253C88428BA32FB0076B6D0 /* HTMLElementsGenerator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTMLElementsGenerator.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>"; };
|
||||
@ -180,6 +182,7 @@
|
||||
E22E87A7289F0E7B00E51191 /* PageGenerator.swift */,
|
||||
E22E879D289EFDFC00E51191 /* OverviewPageGenerator.swift */,
|
||||
E2F8FA1D28A539C500632026 /* MarkdownProcessor.swift */,
|
||||
E253C88428BA32FB0076B6D0 /* HTMLElementsGenerator.swift */,
|
||||
);
|
||||
path = Generators;
|
||||
sourceTree = "<group>";
|
||||
@ -325,6 +328,7 @@
|
||||
E2C5A5D728A022C500102A25 /* TemplateFactory.swift in Sources */,
|
||||
E22E8772289D8C2700E51191 /* IndexPageGenerator.swift in Sources */,
|
||||
E2F8FA3A28AE313A00632026 /* ValidationLog.swift in Sources */,
|
||||
E253C88528BA32FB0076B6D0 /* HTMLElementsGenerator.swift in Sources */,
|
||||
E2C5A5D528A0223C00102A25 /* HeaderTemplate.swift in Sources */,
|
||||
E22E876C289D855D00E51191 /* ThumbnailStyle.swift in Sources */,
|
||||
E2F8FA2D28AD2F5300632026 /* GenericMetadata.swift in Sources */,
|
||||
|
12
WebsiteGenerator/Generators/HTMLElementsGenerator.swift
Normal file
12
WebsiteGenerator/Generators/HTMLElementsGenerator.swift
Normal file
@ -0,0 +1,12 @@
|
||||
import Foundation
|
||||
|
||||
struct HTMLElementsGenerator {
|
||||
|
||||
init() {
|
||||
|
||||
}
|
||||
|
||||
func make(title: String, suffix: String) -> String {
|
||||
"\(title)<span class=\"suffix\">\(suffix)</span>"
|
||||
}
|
||||
}
|
@ -20,7 +20,7 @@ struct IndexPageGenerator {
|
||||
content[.head] = factory.pageHead.generate(page: site, language: language)
|
||||
content[.topBar] = factory.topBar.generate(sectionUrl: nil, languageButton: languageButton)
|
||||
content[.contentClass] = "overview"
|
||||
content[.header] = makeHeader(localized: localized)
|
||||
content[.header] = makeHeader(page: site, metadata: localized, language: language)
|
||||
content[.content] = factory.overviewSection.generate(
|
||||
sections: site.elements,
|
||||
in: site,
|
||||
@ -33,12 +33,8 @@ struct IndexPageGenerator {
|
||||
log.add(info: "Generated \(url.lastPathComponent)", source: site.path)
|
||||
}
|
||||
|
||||
private func makeHeader(localized: Element.LocalizedMetadata) -> String {
|
||||
var content = [HeaderKey : String]()
|
||||
content[.title] = localized.title
|
||||
#warning("Add title suffix")
|
||||
content[.subtitle] = localized.subtitle
|
||||
content[.titleText] = localized.description
|
||||
private func makeHeader(page: Element, metadata: Element.LocalizedMetadata, language: String) -> String {
|
||||
let content = factory.makeHeaderContent(page: page, metadata: metadata, language: language)
|
||||
return factory.factory.centeredHeader.generate(content)
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ struct OverviewPageGenerator {
|
||||
sectionUrl: section.sectionUrl(for: language),
|
||||
languageButton: languageButton)
|
||||
content[.contentClass] = "overview"
|
||||
content[.header] = makeHeader(metadata: metadata, language: language, backText: backLinkText)
|
||||
content[.header] = makeHeader(page: section, metadata: metadata, language: language)
|
||||
content[.content] = makeContent(section: section, language: language)
|
||||
content[.footer] = section.customFooterContent()
|
||||
guard factory.page.generate(content, to: url) else {
|
||||
@ -45,15 +45,8 @@ struct OverviewPageGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
private func makeHeader(metadata: Element.LocalizedMetadata,
|
||||
language: String,
|
||||
backText: String?) -> String {
|
||||
var content = [HeaderKey : String]()
|
||||
content[.title] = metadata.title
|
||||
#warning("Add title suffix")
|
||||
content[.subtitle] = metadata.subtitle
|
||||
content[.titleText] = metadata.description
|
||||
content[.backLink] = backText.unwrapped { factory.makeBackLink(text: $0, language: language) }
|
||||
private func makeHeader(page: Element, metadata: Element.LocalizedMetadata, language: String) -> String {
|
||||
let content = factory.makeHeaderContent(page: page, metadata: metadata, language: language)
|
||||
return factory.factory.centeredHeader.generate(content)
|
||||
}
|
||||
}
|
||||
|
@ -61,21 +61,8 @@ struct PageGenerator {
|
||||
}
|
||||
|
||||
private func makeHeader(page: Element, metadata: Element.LocalizedMetadata, language: String) -> String {
|
||||
let backText = page.backLinkText(for: language)
|
||||
|
||||
var content = [HeaderKey : String]()
|
||||
content[.backLink] = factory.makeBackLink(text: backText, language: language)
|
||||
if let suffix = metadata.titleSuffix {
|
||||
content[.title] = make(title: metadata.title, suffix: suffix)
|
||||
} else {
|
||||
content[.title] = metadata.title
|
||||
}
|
||||
content[.subtitle] = metadata.subtitle
|
||||
content[.date] = factory.makeDateString(start: page.date, end: page.endDate)
|
||||
let content = factory.makeHeaderContent(page: page, metadata: metadata, language: language)
|
||||
return factory.factory.leftHeader.generate(content)
|
||||
}
|
||||
|
||||
private func make(title: String, suffix: String) -> String {
|
||||
"\(title)<span class=\"suffix\">\(suffix)</span>"
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ struct ThumbnailListGenerator {
|
||||
private func itemContent(_ item: Element, parent: Element, language: String, style: ThumbnailStyle) -> String {
|
||||
let fullThumbnailPath = item.thumbnailFilePath(for: language)
|
||||
let relativeImageUrl = parent.relativePathToFileWithPath(fullThumbnailPath)
|
||||
|
||||
let metadata = item.localized(for: language)
|
||||
var content = [ThumbnailKey : String]()
|
||||
|
||||
if item.state.hasThumbnailLink {
|
||||
@ -27,8 +27,11 @@ struct ThumbnailListGenerator {
|
||||
}
|
||||
|
||||
content[.image] = relativeImageUrl
|
||||
content[.title] = item.title(for: language)
|
||||
#warning("Generate thumbnail suffix")
|
||||
if style == .large, let suffix = metadata.thumbnailSuffix {
|
||||
content[.title] = factory.html.make(title: metadata.title, suffix: suffix)
|
||||
} else {
|
||||
content[.title] = metadata.title
|
||||
}
|
||||
content[.image2x] = relativeImageUrl.insert("@2x", beforeLast: ".")
|
||||
content[.corner] = item.cornerText(for: language).unwrapped {
|
||||
factory.largeThumbnail.makeCorner(text: $0)
|
||||
|
@ -142,5 +142,20 @@ struct LocalizedSiteTemplate {
|
||||
return fullDateFormatter.string(from: start)
|
||||
.insert(" - \(day.string(from: end))", beforeLast: ",")
|
||||
}
|
||||
|
||||
func makeHeaderContent(page: Element, metadata: Element.LocalizedMetadata, language: String) -> [HeaderKey : String] {
|
||||
let backText = page.backLinkText(for: language)
|
||||
|
||||
var content = [HeaderKey : String]()
|
||||
content[.backLink] = makeBackLink(text: backText, language: language)
|
||||
if let suffix = metadata.titleSuffix {
|
||||
content[.title] = factory.html.make(title: metadata.title, suffix: suffix)
|
||||
} else {
|
||||
content[.title] = metadata.title
|
||||
}
|
||||
content[.subtitle] = metadata.subtitle
|
||||
content[.date] = makeDateString(start: page.date, end: page.endDate)
|
||||
return content
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,10 @@ final class TemplateFactory {
|
||||
|
||||
let video: PageVideoTemplate
|
||||
|
||||
// MARK: HTML
|
||||
|
||||
let html: HTMLElementsGenerator
|
||||
|
||||
// MARK: Init
|
||||
|
||||
init(templateFolder: URL) throws {
|
||||
@ -69,5 +73,6 @@ final class TemplateFactory {
|
||||
self.page = try .init(in: templateFolder)
|
||||
self.image = try .init(in: templateFolder)
|
||||
self.video = try .init(in: templateFolder)
|
||||
self.html = .init()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user