Fix script imports

This commit is contained in:
Christoph Hagen 2023-12-18 21:30:39 +01:00
parent 54a4d6dbc3
commit ddf489c2c4
3 changed files with 15 additions and 6 deletions

View File

@ -99,8 +99,11 @@ struct HTMLElementsGenerator {
""" """
} }
func scriptInclude(path: String) -> String { func scriptInclude(path: String, asModule: Bool) -> String {
"<script src=\"\(path)\"></script>" if asModule {
return "<script type=\"module\" src=\"\(path)\"></script>"
}
return "<script src=\"\(path)\"></script>"
} }
func codeHighlightFooter() -> String { func codeHighlightFooter() -> String {

View File

@ -38,12 +38,11 @@ struct PageHeadGenerator {
content[.customPageContent] = results.getContentOfOptionalFile(at: page.additionalHeadContentPath, source: page.path) content[.customPageContent] = results.getContentOfOptionalFile(at: page.additionalHeadContentPath, source: page.path)
let head = (content[.customPageContent].unwrapped { [$0] } ?? []) + headers let head = (content[.customPageContent].unwrapped { [$0] } ?? []) + headers
.map { $0.rawValue } .sorted { $0.rawValue < $1.rawValue }
.sorted()
.map { option in .map { option in
let scriptPath = "assets/js/\(option)" let scriptPath = "assets/js/\(option.rawValue)"
let relative = page.relativePathToOtherSiteElement(file: scriptPath) 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") content[.customPageContent] = head.joined(separator: "\n")

View File

@ -3,6 +3,13 @@ import Foundation
enum HeaderFile: String { enum HeaderFile: String {
case codeHightlighting = "highlight.js" case codeHightlighting = "highlight.js"
case modelViewer = "model-viewer.js" case modelViewer = "model-viewer.js"
var asModule: Bool {
switch self {
case .codeHightlighting: return false
case .modelViewer: return true
}
}
} }
typealias RequiredHeaders = Set<HeaderFile> typealias RequiredHeaders = Set<HeaderFile>