Skip to content

Commit 9028f92

Browse files
committed
fix: script's now follow the Script structure
1 parent 06d2355 commit 9028f92

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

Sources/WebUI/Core/Document.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public struct Document {
4141
private let logger = Logger(label: "com.webui.document")
4242
public let path: String?
4343
public var metadata: Metadata
44-
public var scripts: [String: ScriptAttribute?]?
44+
public var scripts: [Script]?
4545
public var stylesheets: [String]?
4646
public var theme: Theme?
4747
public let head: String?
@@ -84,7 +84,7 @@ public struct Document {
8484
public init(
8585
path: String? = nil,
8686
metadata: Metadata,
87-
scripts: [String: ScriptAttribute?]? = nil,
87+
scripts: [Script]? = nil,
8888
stylesheets: [String]? = nil,
8989
theme: Theme? = nil,
9090
head: String? = nil,
@@ -131,7 +131,7 @@ public struct Document {
131131
logger.trace("Adding \(scripts.count) script tags")
132132
for script in scripts {
133133
optionalTags.append(
134-
"<script \(script.value?.rawValue ?? "") src=\"\(script.key)\"></script>"
134+
"<script \(script.attribute?.rawValue ?? "") src=\"\(script.src)\"></script>"
135135
)
136136
}
137137
}
@@ -156,7 +156,7 @@ public struct Document {
156156
\(optionalTags.joined(separator: "\n"))
157157
<script src="https://unpkg.com/@tailwindcss/browser@4"></script>
158158
\(head ?? "")
159-
</head>
159+
</head>
160160
<body>
161161
\(content.map { $0.render() }.joined())
162162
</body>

Sources/WebUI/Core/Website.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public struct Website {
2020
public let stylesheets: [String]?
2121

2222
/// Optional JavaScript sources with their loading attributes applied to all routes.
23-
public let scripts: [String: ScriptAttribute?]?
23+
public let scripts: [Script]?
2424

2525
/// Optional custom HTML to append to all document head sections.
2626
public let head: String?
@@ -76,7 +76,7 @@ public struct Website {
7676
metadata: Metadata? = nil,
7777
theme: Theme? = nil,
7878
stylesheets: [String]? = nil,
79-
scripts: [String: ScriptAttribute?]? = nil,
79+
scripts: [Script]? = nil,
8080
head: String? = nil,
8181
routes: [Document],
8282
baseURL: String? = nil,
@@ -97,10 +97,9 @@ public struct Website {
9797
self.robotsRules = robotsRules
9898
self.routes = routes.map { document in
9999
// Merge scripts: Website scripts + Document scripts (Document scripts override duplicates)
100-
var mergedScripts = scripts ?? [:]
101-
if let documentScripts = document.scripts {
102-
mergedScripts.merge(documentScripts) { _, new in new }
103-
}
100+
let mergedScripts = Array(
101+
(scripts ?? []) + (document.scripts ?? [])
102+
)
104103

105104
// Merge stylesheets: Website stylesheets + Document stylesheets (combine, remove duplicates)
106105
let mergedStylesheets = Array(

Tests/WebUITests/Core/DocumentTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ import Testing
152152
description: "Testing script inclusion"
153153
),
154154
scripts: [
155-
"https://cdn.example.com/script1.js": .async,
156-
"/public/script2.js": .defer,
155+
Script(src: "https://cdn.example.com/script1.js", attribute: .async),
156+
Script(src: "/public/script2.js", attribute: .defer),
157157
]
158158
) {
159159
"Script Test"

0 commit comments

Comments
 (0)