Compare commits
No commits in common. "54a4d6dbc378c39707d0fe8a509b7cca584db2a2" and "1d97560c40516062321f55887b06ae5aea29bc1a" have entirely different histories.
54a4d6dbc3
...
1d97560c40
@ -319,7 +319,7 @@ struct Element {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getExternalPageMap(language: String, log: MetadataInfoLogger) -> [String : String] {
|
func getExternalPageMap(language: String) -> [String : String] {
|
||||||
var result = [String : String]()
|
var result = [String : String]()
|
||||||
if let ext = getExternalLink(for: language) {
|
if let ext = getExternalLink(for: language) {
|
||||||
result[id] = ext
|
result[id] = ext
|
||||||
@ -327,10 +327,7 @@ struct Element {
|
|||||||
result[id] = path + Element.htmlPagePathAddition(for: language)
|
result[id] = path + Element.htmlPagePathAddition(for: language)
|
||||||
}
|
}
|
||||||
elements.forEach { element in
|
elements.forEach { element in
|
||||||
element.getExternalPageMap(language: language, log: log).forEach { key, value in
|
element.getExternalPageMap(language: language).forEach { key, value in
|
||||||
if result[key] != nil {
|
|
||||||
log.error("Page id '\(key)' is used twice", source: value)
|
|
||||||
}
|
|
||||||
result[key] = value
|
result[key] = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,32 +4,6 @@ import Splash
|
|||||||
|
|
||||||
struct PageContentGenerator {
|
struct PageContentGenerator {
|
||||||
|
|
||||||
private let factory: TemplateFactory
|
|
||||||
|
|
||||||
private let siteRoot: Element
|
|
||||||
|
|
||||||
private let results: GenerationResultsHandler
|
|
||||||
|
|
||||||
init(factory: TemplateFactory, siteRoot: Element, results: GenerationResultsHandler) {
|
|
||||||
self.factory = factory
|
|
||||||
self.siteRoot = siteRoot
|
|
||||||
self.results = results
|
|
||||||
}
|
|
||||||
|
|
||||||
func generate(page: Element, language: String, content: String) -> (content: String, headers: RequiredHeaders) {
|
|
||||||
let parser = PageContentParser(
|
|
||||||
factory: factory,
|
|
||||||
siteRoot: siteRoot,
|
|
||||||
results: results,
|
|
||||||
page: page,
|
|
||||||
language: language)
|
|
||||||
return parser.generatePage(from: content)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
final class PageContentParser {
|
|
||||||
|
|
||||||
private let pageLinkMarker = "page:"
|
private let pageLinkMarker = "page:"
|
||||||
|
|
||||||
private let largeImageIndicator = "*large*"
|
private let largeImageIndicator = "*large*"
|
||||||
@ -42,52 +16,42 @@ final class PageContentParser {
|
|||||||
|
|
||||||
private let results: GenerationResultsHandler
|
private let results: GenerationResultsHandler
|
||||||
|
|
||||||
private let page: Element
|
init(factory: TemplateFactory, siteRoot: Element, results: GenerationResultsHandler) {
|
||||||
|
|
||||||
private let language: String
|
|
||||||
|
|
||||||
private var headers = RequiredHeaders()
|
|
||||||
|
|
||||||
private var largeImageCount: Int = 0
|
|
||||||
|
|
||||||
init(factory: TemplateFactory, siteRoot: Element, results: GenerationResultsHandler, page: Element, language: String) {
|
|
||||||
self.factory = factory
|
self.factory = factory
|
||||||
self.siteRoot = siteRoot
|
self.siteRoot = siteRoot
|
||||||
self.results = results
|
self.results = results
|
||||||
self.page = page
|
|
||||||
self.language = language
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func generatePage(from content: String) -> (content: String, headers: RequiredHeaders) {
|
func generate(page: Element, language: String, content: String) -> (content: String, includesCode: Bool) {
|
||||||
headers = .init()
|
var hasCodeContent = false
|
||||||
|
var largeImageCount = 0
|
||||||
|
|
||||||
let imageModifier = Modifier(target: .images) { html, markdown in
|
let imageModifier = Modifier(target: .images) { html, markdown in
|
||||||
self.processMarkdownImage(markdown: markdown, html: html)
|
processMarkdownImage(markdown: markdown, html: html, page: page, language: language, largeImageCount: &largeImageCount)
|
||||||
}
|
}
|
||||||
let codeModifier = Modifier(target: .codeBlocks) { html, markdown in
|
let codeModifier = Modifier(target: .codeBlocks) { html, markdown in
|
||||||
if markdown.starts(with: "```swift") {
|
if markdown.starts(with: "```swift") {
|
||||||
let code = markdown.between("```swift", and: "```").trimmed
|
let code = markdown.between("```swift", and: "```").trimmed
|
||||||
return "<pre><code>" + self.swift.highlight(code) + "</pre></code>"
|
return "<pre><code>" + swift.highlight(code) + "</pre></code>"
|
||||||
}
|
}
|
||||||
self.headers.insert(.codeHightlighting)
|
hasCodeContent = true
|
||||||
return html
|
return html
|
||||||
}
|
}
|
||||||
let linkModifier = Modifier(target: .links) { html, markdown in
|
let linkModifier = Modifier(target: .links) { html, markdown in
|
||||||
self.handleLink(html: html, markdown: markdown)
|
handleLink(page: page, language: language, html: html, markdown: markdown)
|
||||||
}
|
}
|
||||||
let htmlModifier = Modifier(target: .html) { html, markdown in
|
let htmlModifier = Modifier(target: .html) { html, markdown in
|
||||||
self.handleHTML(html: html, markdown: markdown)
|
handleHTML(page: page, language: language, html: html, markdown: markdown)
|
||||||
}
|
}
|
||||||
let headlinesModifier = Modifier(target: .headings) { html, markdown in
|
let headlinesModifier = Modifier(target: .headings) { html, markdown in
|
||||||
self.handleHeadlines(html: html, markdown: markdown)
|
handleHeadlines(page: page, language: language, html: html, markdown: markdown)
|
||||||
}
|
}
|
||||||
|
|
||||||
let parser = MarkdownParser(modifiers: [imageModifier, codeModifier, linkModifier, htmlModifier, headlinesModifier])
|
let parser = MarkdownParser(modifiers: [imageModifier, codeModifier, linkModifier, htmlModifier, headlinesModifier])
|
||||||
return (parser.html(from: content), headers)
|
return (parser.html(from: content), hasCodeContent)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func handleLink(html: String, markdown: Substring) -> String {
|
private func handleLink(page: Element, language: String, html: String, markdown: Substring) -> String {
|
||||||
let file = markdown.between("(", and: ")")
|
let file = markdown.between("(", and: ")")
|
||||||
if file.hasPrefix(pageLinkMarker) {
|
if file.hasPrefix(pageLinkMarker) {
|
||||||
let textToChange = file.dropAfterFirst("#")
|
let textToChange = file.dropAfterFirst("#")
|
||||||
@ -108,7 +72,7 @@ final class PageContentParser {
|
|||||||
return html
|
return html
|
||||||
}
|
}
|
||||||
|
|
||||||
private func handleHTML(html: String, markdown: Substring) -> String {
|
private func handleHTML(page: Element, language: String, html: String, markdown: Substring) -> String {
|
||||||
// TODO: Check HTML code in markdown for required resources
|
// TODO: Check HTML code in markdown for required resources
|
||||||
//print("[HTML] Found in page \(page.path):")
|
//print("[HTML] Found in page \(page.path):")
|
||||||
//print(markdown)
|
//print(markdown)
|
||||||
@ -119,7 +83,7 @@ final class PageContentParser {
|
|||||||
return html
|
return html
|
||||||
}
|
}
|
||||||
|
|
||||||
private func handleHeadlines(html: String, markdown: Substring) -> String {
|
private func handleHeadlines(page: Element, language: String, html: String, markdown: Substring) -> String {
|
||||||
let id = markdown
|
let id = markdown
|
||||||
.last(after: "#")
|
.last(after: "#")
|
||||||
.trimmed
|
.trimmed
|
||||||
@ -132,7 +96,7 @@ final class PageContentParser {
|
|||||||
return parts[0] + " id=\"\(id)\">" + parts.dropFirst().joined(separator: ">")
|
return parts[0] + " id=\"\(id)\">" + parts.dropFirst().joined(separator: ">")
|
||||||
}
|
}
|
||||||
|
|
||||||
private func processMarkdownImage(markdown: Substring, html: String) -> String {
|
private func processMarkdownImage(markdown: Substring, html: String, page: Element, language: String, largeImageCount: inout Int) -> String {
|
||||||
// Split the markdown ![alt](file title)
|
// Split the markdown ![alt](file title)
|
||||||
// There are several known shorthand commands
|
// There are several known shorthand commands
|
||||||
// For images: ![*large* left_title](file right_title)
|
// For images: ![*large* left_title](file right_title)
|
||||||
@ -149,7 +113,7 @@ final class PageContentParser {
|
|||||||
}
|
}
|
||||||
let alt = markdown.between("[", and: "]").nonEmpty?.removingPercentEncoding
|
let alt = markdown.between("[", and: "]").nonEmpty?.removingPercentEncoding
|
||||||
if let alt = alt, let command = ShorthandMarkdownKey(rawValue: alt) {
|
if let alt = alt, let command = ShorthandMarkdownKey(rawValue: alt) {
|
||||||
return handleShortHandCommand(command, content: fileAndTitle)
|
return handleShortHandCommand(command, page: page, language: language, content: fileAndTitle)
|
||||||
}
|
}
|
||||||
|
|
||||||
let file = fileAndTitle.dropAfterFirst(" ")
|
let file = fileAndTitle.dropAfterFirst(" ")
|
||||||
@ -157,39 +121,39 @@ final class PageContentParser {
|
|||||||
|
|
||||||
let fileExtension = file.lastComponentAfter(".").lowercased()
|
let fileExtension = file.lastComponentAfter(".").lowercased()
|
||||||
if let _ = ImageType(fileExtension: fileExtension) {
|
if let _ = ImageType(fileExtension: fileExtension) {
|
||||||
return handleImage(file: file, rightTitle: title, leftTitle: alt, largeImageCount: &largeImageCount)
|
return handleImage(page: page, file: file, rightTitle: title, leftTitle: alt, largeImageCount: &largeImageCount)
|
||||||
}
|
}
|
||||||
if let _ = VideoType(rawValue: fileExtension) {
|
if let _ = VideoType(rawValue: fileExtension) {
|
||||||
return handleVideo(file: file, optionString: alt)
|
return handleVideo(page: page, file: file, optionString: alt)
|
||||||
}
|
}
|
||||||
switch fileExtension {
|
switch fileExtension {
|
||||||
case "svg":
|
case "svg":
|
||||||
return handleSvg(file: file, area: alt)
|
return handleSvg(page: page, file: file, area: alt)
|
||||||
case "gif":
|
case "gif":
|
||||||
return handleGif(file: file, altText: alt ?? "gif image")
|
return handleGif(page: page, file: file, altText: alt ?? "gif image")
|
||||||
default:
|
default:
|
||||||
return handleFile(file: file, fileExtension: fileExtension)
|
return handleFile(page: page, file: file, fileExtension: fileExtension)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func handleShortHandCommand(_ command: ShorthandMarkdownKey, content: String) -> String {
|
private func handleShortHandCommand(_ command: ShorthandMarkdownKey, page: Element, language: String, content: String) -> String {
|
||||||
switch command {
|
switch command {
|
||||||
case .downloadButtons:
|
case .downloadButtons:
|
||||||
return handleDownloadButtons(content: content)
|
return handleDownloadButtons(page: page, content: content)
|
||||||
case .externalLink:
|
case .externalLink:
|
||||||
return handleExternalButtons(content: content)
|
return handleExternalButtons(page: page, content: content)
|
||||||
case .includedHtml:
|
case .includedHtml:
|
||||||
return handleExternalHTML(file: content)
|
return handleExternalHTML(page: page, file: content)
|
||||||
case .box:
|
case .box:
|
||||||
return handleSimpleBox(content: content)
|
return handleSimpleBox(page: page, content: content)
|
||||||
case .pageLink:
|
case .pageLink:
|
||||||
return handlePageLink(pageId: content)
|
return handlePageLink(page: page, language: language, pageId: content)
|
||||||
case .model3d:
|
case .model3d:
|
||||||
return handle3dModel(content: content)
|
return handle3dModel(page: page, content: content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func handleImage(file: String, rightTitle: String?, leftTitle: String?, largeImageCount: inout Int) -> String {
|
private func handleImage(page: Element, file: String, rightTitle: String?, leftTitle: String?, largeImageCount: inout Int) -> String {
|
||||||
let imagePath = page.pathRelativeToRootForContainedInputFile(file)
|
let imagePath = page.pathRelativeToRootForContainedInputFile(file)
|
||||||
let left: String
|
let left: String
|
||||||
let createFullScreenVersion: Bool
|
let createFullScreenVersion: Bool
|
||||||
@ -230,7 +194,7 @@ final class PageContentParser {
|
|||||||
return factory.largeImage.generate(content)
|
return factory.largeImage.generate(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func handleVideo(file: String, optionString: String?) -> String {
|
private func handleVideo(page: Element, file: String, optionString: String?) -> String {
|
||||||
let options: [PageVideoTemplate.VideoOption] = optionString.unwrapped { string in
|
let options: [PageVideoTemplate.VideoOption] = optionString.unwrapped { string in
|
||||||
string.components(separatedBy: " ").compactMap { optionText -> PageVideoTemplate.VideoOption? in
|
string.components(separatedBy: " ").compactMap { optionText -> PageVideoTemplate.VideoOption? in
|
||||||
guard let optionText = optionText.trimmed.nonEmpty else {
|
guard let optionText = optionText.trimmed.nonEmpty else {
|
||||||
@ -281,7 +245,7 @@ final class PageContentParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func handleGif(file: String, altText: String) -> String {
|
private func handleGif(page: Element, file: String, altText: String) -> String {
|
||||||
let imagePath = page.pathRelativeToRootForContainedInputFile(file)
|
let imagePath = page.pathRelativeToRootForContainedInputFile(file)
|
||||||
results.require(file: imagePath, source: page.path)
|
results.require(file: imagePath, source: page.path)
|
||||||
|
|
||||||
@ -293,7 +257,7 @@ final class PageContentParser {
|
|||||||
return factory.html.image(file: file, width: width, height: height, altText: altText)
|
return factory.html.image(file: file, width: width, height: height, altText: altText)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func handleSvg(file: String, area: String?) -> String {
|
private func handleSvg(page: Element, file: String, area: String?) -> String {
|
||||||
let imagePath = page.pathRelativeToRootForContainedInputFile(file)
|
let imagePath = page.pathRelativeToRootForContainedInputFile(file)
|
||||||
results.require(file: imagePath, source: page.path)
|
results.require(file: imagePath, source: page.path)
|
||||||
|
|
||||||
@ -330,12 +294,12 @@ final class PageContentParser {
|
|||||||
return factory.html.svgImage(file: file, part: part, altText: altText)
|
return factory.html.svgImage(file: file, part: part, altText: altText)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func handleFile(file: String, fileExtension: String) -> String {
|
private func handleFile(page: Element, file: String, fileExtension: String) -> String {
|
||||||
results.warning("Unhandled file \(file) with extension \(fileExtension)", source: page.path)
|
results.warning("Unhandled file \(file) with extension \(fileExtension)", source: page.path)
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
private func handleDownloadButtons(content: String) -> String {
|
private func handleDownloadButtons(page: Element, content: String) -> String {
|
||||||
let buttons = content
|
let buttons = content
|
||||||
.components(separatedBy: ";")
|
.components(separatedBy: ";")
|
||||||
.compactMap { button -> (file: String, text: String, downloadName: String?)? in
|
.compactMap { button -> (file: String, text: String, downloadName: String?)? in
|
||||||
@ -357,7 +321,7 @@ final class PageContentParser {
|
|||||||
return factory.html.downloadButtons(buttons)
|
return factory.html.downloadButtons(buttons)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func handleExternalButtons(content: String) -> String {
|
private func handleExternalButtons(page: Element, content: String) -> String {
|
||||||
let buttons = content
|
let buttons = content
|
||||||
.components(separatedBy: ";")
|
.components(separatedBy: ";")
|
||||||
.compactMap { button -> (url: String, text: String)? in
|
.compactMap { button -> (url: String, text: String)? in
|
||||||
@ -377,12 +341,12 @@ final class PageContentParser {
|
|||||||
return factory.html.externalButtons(buttons)
|
return factory.html.externalButtons(buttons)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func handleExternalHTML(file: String) -> String {
|
private func handleExternalHTML(page: Element, file: String) -> String {
|
||||||
let path = page.pathRelativeToRootForContainedInputFile(file)
|
let path = page.pathRelativeToRootForContainedInputFile(file)
|
||||||
return results.getContentOfRequiredFile(at: path, source: page.path) ?? ""
|
return results.getContentOfRequiredFile(at: path, source: page.path) ?? ""
|
||||||
}
|
}
|
||||||
|
|
||||||
private func handleSimpleBox(content: String) -> String {
|
private func handleSimpleBox(page: Element, content: String) -> String {
|
||||||
let parts = content.components(separatedBy: ";")
|
let parts = content.components(separatedBy: ";")
|
||||||
guard parts.count > 1 else {
|
guard parts.count > 1 else {
|
||||||
results.warning("Invalid box specification", source: page.path)
|
results.warning("Invalid box specification", source: page.path)
|
||||||
@ -393,7 +357,7 @@ final class PageContentParser {
|
|||||||
return factory.makePlaceholder(title: title, text: text)
|
return factory.makePlaceholder(title: title, text: text)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func handlePageLink(pageId: String) -> String {
|
private func handlePageLink(page: Element, language: String, pageId: String) -> String {
|
||||||
guard let linkedPage = siteRoot.find(pageId) else {
|
guard let linkedPage = siteRoot.find(pageId) else {
|
||||||
// Checking the page path will add it to the missing pages
|
// Checking the page path will add it to the missing pages
|
||||||
_ = results.getPagePath(for: pageId, source: page.path, language: language)
|
_ = results.getPagePath(for: pageId, source: page.path, language: language)
|
||||||
@ -439,7 +403,7 @@ final class PageContentParser {
|
|||||||
return factory.pageLink.generate(content)
|
return factory.pageLink.generate(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func handle3dModel(content: String) -> String {
|
private func handle3dModel(page: Element, content: String) -> String {
|
||||||
let parts = content.components(separatedBy: ";")
|
let parts = content.components(separatedBy: ";")
|
||||||
guard parts.count > 1 else {
|
guard parts.count > 1 else {
|
||||||
results.warning("Invalid 3d model specification", source: page.path)
|
results.warning("Invalid 3d model specification", source: page.path)
|
||||||
@ -455,9 +419,6 @@ final class PageContentParser {
|
|||||||
let filePath = page.pathRelativeToRootForContainedInputFile(file)
|
let filePath = page.pathRelativeToRootForContainedInputFile(file)
|
||||||
results.require(file: filePath, source: page.path)
|
results.require(file: filePath, source: page.path)
|
||||||
|
|
||||||
// Add required file to head
|
|
||||||
headers.insert(.modelViewer)
|
|
||||||
|
|
||||||
let description = parts.dropFirst().joined(separator: ";")
|
let description = parts.dropFirst().joined(separator: ";")
|
||||||
return """
|
return """
|
||||||
<model-viewer alt="\(description)" src="\(file)" ar shadow-intensity="1" camera-controls touch-action="pan-y"></model-viewer>
|
<model-viewer alt="\(description)" src="\(file)" ar shadow-intensity="1" camera-controls touch-action="pan-y"></model-viewer>
|
||||||
|
@ -24,12 +24,12 @@ struct PageGenerator {
|
|||||||
let inputContentPath = page.path + "/\(language).md"
|
let inputContentPath = page.path + "/\(language).md"
|
||||||
let metadata = page.localized(for: language)
|
let metadata = page.localized(for: language)
|
||||||
let nextLanguage = page.nextLanguage(for: language)
|
let nextLanguage = page.nextLanguage(for: language)
|
||||||
let (pageContent, additionalHeaders) = makeContent(
|
let (pageContent, pageIncludesCode) = makeContent(
|
||||||
page: page, metadata: metadata, language: language, path: inputContentPath)
|
page: page, metadata: metadata, language: language, path: inputContentPath)
|
||||||
|
|
||||||
var content = [PageTemplate.Key : String]()
|
var content = [PageTemplate.Key : String]()
|
||||||
content[.language] = language
|
content[.language] = language
|
||||||
content[.head] = factory.pageHead.generate(page: page, language: language, headers: additionalHeaders)
|
content[.head] = factory.pageHead.generate(page: page, language: language, includesCode: pageIncludesCode)
|
||||||
let sectionUrl = page.sectionUrl(for: language)
|
let sectionUrl = page.sectionUrl(for: language)
|
||||||
content[.topBar] = factory.topBar.generate(sectionUrl: sectionUrl, languageButton: nextLanguage, page: page)
|
content[.topBar] = factory.topBar.generate(sectionUrl: sectionUrl, languageButton: nextLanguage, page: page)
|
||||||
content[.contentClass] = "content"
|
content[.contentClass] = "content"
|
||||||
@ -42,7 +42,7 @@ struct PageGenerator {
|
|||||||
content[.nextPageUrl] = navLink(from: page, to: nextPage, language: language)
|
content[.nextPageUrl] = navLink(from: page, to: nextPage, language: language)
|
||||||
content[.footer] = results.getContentOfOptionalFile(at: page.additionalFooterContentPath, source: page.path)
|
content[.footer] = results.getContentOfOptionalFile(at: page.additionalFooterContentPath, source: page.path)
|
||||||
|
|
||||||
if additionalHeaders.contains(.codeHightlighting) {
|
if pageIncludesCode {
|
||||||
let highlightCode = factory.factory.html.codeHighlightFooter()
|
let highlightCode = factory.factory.html.codeHighlightFooter()
|
||||||
content[.footer] = (content[.footer].unwrapped { $0 + "\n" } ?? "") + highlightCode
|
content[.footer] = (content[.footer].unwrapped { $0 + "\n" } ?? "") + highlightCode
|
||||||
}
|
}
|
||||||
@ -74,7 +74,7 @@ struct PageGenerator {
|
|||||||
return factory.factory.html.makeNextText(text)
|
return factory.factory.html.makeNextText(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func makeContent(page: Element, metadata: Element.LocalizedMetadata, language: String, path: String) -> (content: String, headers: RequiredHeaders) {
|
private func makeContent(page: Element, metadata: Element.LocalizedMetadata, language: String, path: String) -> (content: String, includesCode: Bool) {
|
||||||
if let raw = results.getContentOfMdFile(at: path, source: page.path)?.trimmed.nonEmpty {
|
if let raw = results.getContentOfMdFile(at: path, source: page.path)?.trimmed.nonEmpty {
|
||||||
let (content, includesCode) = contentGenerator.generate(page: page, language: language, content: raw)
|
let (content, includesCode) = contentGenerator.generate(page: page, language: language, content: raw)
|
||||||
return (content, includesCode)
|
return (content, includesCode)
|
||||||
|
@ -14,7 +14,7 @@ struct PageHeadGenerator {
|
|||||||
self.results = results
|
self.results = results
|
||||||
}
|
}
|
||||||
|
|
||||||
func generate(page: Element, language: String, headers: RequiredHeaders = .init()) -> String {
|
func generate(page: Element, language: String, includesCode: Bool = false) -> String {
|
||||||
let metadata = page.localized(for: language)
|
let metadata = page.localized(for: language)
|
||||||
|
|
||||||
var content = [PageHeadTemplate.Key : String]()
|
var content = [PageHeadTemplate.Key : String]()
|
||||||
@ -36,17 +36,17 @@ struct PageHeadGenerator {
|
|||||||
content[.image] = factory.html.linkPreviewImage(file: linkPreviewImageName)
|
content[.image] = factory.html.linkPreviewImage(file: linkPreviewImageName)
|
||||||
}
|
}
|
||||||
content[.customPageContent] = results.getContentOfOptionalFile(at: page.additionalHeadContentPath, source: page.path)
|
content[.customPageContent] = results.getContentOfOptionalFile(at: page.additionalHeadContentPath, source: page.path)
|
||||||
|
if includesCode {
|
||||||
let head = (content[.customPageContent].unwrapped { [$0] } ?? []) + headers
|
let scriptPath = "assets/js/highlight.js"
|
||||||
.map { $0.rawValue }
|
let relative = page.relativePathToOtherSiteElement(file: scriptPath)
|
||||||
.sorted()
|
let includeText = factory.html.scriptInclude(path: relative)
|
||||||
.map { option in
|
if let head = content[.customPageContent] {
|
||||||
let scriptPath = "assets/js/\(option)"
|
content[.customPageContent] = head + "\n" + includeText
|
||||||
let relative = page.relativePathToOtherSiteElement(file: scriptPath)
|
} else {
|
||||||
return factory.html.scriptInclude(path: relative)
|
content[.customPageContent] = includeText
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
content[.customPageContent] = head.joined(separator: "\n")
|
|
||||||
return factory.pageHead.generate(content)
|
return factory.pageHead.generate(content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
import Foundation
|
|
||||||
|
|
||||||
enum HeaderFile: String {
|
|
||||||
case codeHightlighting = "highlight.js"
|
|
||||||
case modelViewer = "model-viewer.js"
|
|
||||||
}
|
|
||||||
|
|
||||||
typealias RequiredHeaders = Set<HeaderFile>
|
|
@ -53,10 +53,7 @@ private func loadSiteData(in folder: URL, runFolder: URL) throws -> (root: Eleme
|
|||||||
print(" Error: No site root loaded, aborting generation")
|
print(" Error: No site root loaded, aborting generation")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
let pageMap = root.languages.map { language in
|
let pageMap = root.languages.map { (language: $0.language, pages: root.getExternalPageMap(language: $0.language)) }
|
||||||
(language: language.language,
|
|
||||||
pages: root.getExternalPageMap(language: language.language, log: log))
|
|
||||||
}
|
|
||||||
log.printMetadataScanOverview(languages: root.languages.count)
|
log.printMetadataScanOverview(languages: root.languages.count)
|
||||||
return (root, pageMap)
|
return (root, pageMap)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user