From ddf489c2c4abf1931660f9078128956c7f1ee1c1 Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Mon, 18 Dec 2023 21:30:39 +0100 Subject: [PATCH] Fix script imports --- Sources/Generator/Generators/HTMLElementsGenerator.swift | 7 +++++-- Sources/Generator/Generators/PageHeadGenerator.swift | 7 +++---- Sources/Generator/Processing/RequiredHeaders.swift | 7 +++++++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Sources/Generator/Generators/HTMLElementsGenerator.swift b/Sources/Generator/Generators/HTMLElementsGenerator.swift index 942bfbc..9352d0e 100644 --- a/Sources/Generator/Generators/HTMLElementsGenerator.swift +++ b/Sources/Generator/Generators/HTMLElementsGenerator.swift @@ -99,8 +99,11 @@ struct HTMLElementsGenerator { """ } - func scriptInclude(path: String) -> String { - "" + func scriptInclude(path: String, asModule: Bool) -> String { + if asModule { + return "" + } + return "" } func codeHighlightFooter() -> String { diff --git a/Sources/Generator/Generators/PageHeadGenerator.swift b/Sources/Generator/Generators/PageHeadGenerator.swift index a8a0ac1..8503931 100644 --- a/Sources/Generator/Generators/PageHeadGenerator.swift +++ b/Sources/Generator/Generators/PageHeadGenerator.swift @@ -38,12 +38,11 @@ struct PageHeadGenerator { content[.customPageContent] = results.getContentOfOptionalFile(at: page.additionalHeadContentPath, source: page.path) let head = (content[.customPageContent].unwrapped { [$0] } ?? []) + headers - .map { $0.rawValue } - .sorted() + .sorted { $0.rawValue < $1.rawValue } .map { option in - let scriptPath = "assets/js/\(option)" + let scriptPath = "assets/js/\(option.rawValue)" let relative = page.relativePathToOtherSiteElement(file: scriptPath) - return factory.html.scriptInclude(path: relative) + return factory.html.scriptInclude(path: relative, asModule: option.asModule) } content[.customPageContent] = head.joined(separator: "\n") diff --git a/Sources/Generator/Processing/RequiredHeaders.swift b/Sources/Generator/Processing/RequiredHeaders.swift index 473da3b..f3a7702 100644 --- a/Sources/Generator/Processing/RequiredHeaders.swift +++ b/Sources/Generator/Processing/RequiredHeaders.swift @@ -3,6 +3,13 @@ import Foundation enum HeaderFile: String { case codeHightlighting = "highlight.js" case modelViewer = "model-viewer.js" + + var asModule: Bool { + switch self { + case .codeHightlighting: return false + case .modelViewer: return true + } + } } typealias RequiredHeaders = Set