Skip to content

Commit f7eeebe

Browse files
authored
feat!: release version 1.0.0
2 parents 8452561 + 7797cab commit f7eeebe

File tree

15 files changed

+276
-385
lines changed

15 files changed

+276
-385
lines changed

.spi.yml

Lines changed: 0 additions & 4 deletions
This file was deleted.

Package.resolved

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import PackageDescription
44

55
let package = Package(
66
name: "web-ui",
7+
platforms: [.macOS(.v15), .iOS(.v13), .tvOS(.v13)],
78
products: [
89
.library(name: "WebUI", targets: ["WebUI"])
910
],

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# WebUI
2-
31
<h2 align="center">
42
<a href="https://github.com/dec0dOS/amazing-github-template">
53
<img src="https://github.com/user-attachments/assets/657945a9-5540-4abb-a107-4f6547e4a77e" alt="Logo" width="300">

Sources/WebUI/Core/Application.swift

Lines changed: 0 additions & 243 deletions
This file was deleted.

Sources/WebUI/Core/Document.swift

Lines changed: 17 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ public enum ScriptAttribute: String {
88
case async
99
}
1010

11+
public struct Script {
12+
let src: String
13+
let attribute: ScriptAttribute?
14+
}
15+
1116
/// Represents an immutable HTML document with metadata and content.
1217
public struct Document {
1318
private let logger = Logger(label: "com.webui.document")
@@ -17,7 +22,7 @@ public struct Document {
1722
public var stylesheets: [String]?
1823
public var theme: Theme?
1924
public let head: String?
20-
private let contentBuilder: () -> [any HTML]
25+
public let contentBuilder: () -> [any HTML]
2126

2227
/// Computed HTML content from the content builder.
2328
var content: [any HTML] {
@@ -69,91 +74,39 @@ public struct Document {
6974
logger.debug("Rendering document: \(path ?? "index")")
7075
logger.trace("Starting metadata rendering")
7176

72-
var optionalMetaTags: [String] = []
73-
if let image = metadata.image, !image.isEmpty {
74-
logger.trace("Adding og:image meta tag: \(image)")
75-
optionalMetaTags.append(
76-
"<meta property=\"og:image\" content=\"\(image)\">"
77-
)
78-
}
79-
if let author = metadata.author, !author.isEmpty {
80-
logger.trace("Adding author meta tag: \(author)")
81-
optionalMetaTags.append("<meta name=\"author\" content=\"\(author)\">")
82-
}
83-
if let twitter = metadata.twitter, !twitter.isEmpty {
84-
logger.trace("Adding twitter meta tag: \(twitter)")
85-
optionalMetaTags.append(
86-
"<meta name=\"twitter:creator\" content=\"@\(twitter)\">"
87-
)
88-
}
89-
if let keywords = metadata.keywords, !keywords.isEmpty {
90-
logger.trace("Adding keywords meta tag with \(keywords.count) keywords")
91-
optionalMetaTags.append(
92-
"<meta name=\"keywords\" content=\"\(keywords.joined(separator: ", "))\">"
93-
)
94-
}
95-
if let themeColor = metadata.themeColor {
96-
logger.trace("Adding theme-color meta tags")
97-
optionalMetaTags.append(
98-
"<meta name=\"theme-color\" content=\"\(themeColor.light)\" media=\"(prefers-color-scheme: light)\">"
99-
)
100-
optionalMetaTags.append(
101-
"<meta name=\"theme-color\" content=\"\(themeColor.dark)\" media=\"(prefers-color-scheme: dark)\">"
102-
)
103-
}
77+
var optionalTags: [String] = metadata.tags + []
10478
if let scripts = scripts {
10579
logger.trace("Adding \(scripts.count) script tags")
10680
for script in scripts {
107-
optionalMetaTags.append(
81+
optionalTags.append(
10882
"<script \(script.value?.rawValue ?? "") src=\"\(script.key)\"></script>"
10983
)
11084
}
11185
}
11286
if let stylesheets = stylesheets {
11387
logger.trace("Adding \(stylesheets.count) stylesheet links")
11488
for stylesheet in stylesheets {
115-
optionalMetaTags.append(
89+
optionalTags.append(
11690
"<link rel=\"stylesheet\" href=\"\(stylesheet)\">"
11791
)
11892
}
11993
}
12094

121-
logger.trace("Building head section")
122-
let headSection = """
95+
logger.debug("Document rendered successfully: \(metadata.pageTitle)")
96+
97+
return """
98+
<!DOCTYPE html>
99+
<html lang="\(metadata.locale.rawValue)">
123100
<head>
124101
<meta charset="UTF-8">
125102
<meta name="viewport" content="width=device-width, initial-scale=1.0">
126103
<title>\(metadata.pageTitle)</title>
127-
<meta property="og:title" content="\(metadata.pageTitle)">
128-
<meta name="description" content="\(metadata.description)">
129-
<meta property="og:description" content="\(metadata.description)">
130-
"<meta property=\"og:type\" content=\"\(metadata.type.rawValue)\">"
131-
<meta name="twitter:card" content="summary_large_image">
132-
\(optionalMetaTags.joined(separator: "\n"))
104+
\(optionalTags.joined(separator: "\n"))
133105
<script src="https://unpkg.com/@tailwindcss/browser@4"></script>
134-
<style type="text/tailwindcss">
135-
@theme {
136-
--breakpoint-xs: 30rem;
137-
--breakpoint-3xl: 120rem;
138-
--breakpoint-4xl: 160rem;
139-
\(theme?.generateCSS() ?? "")
140-
@custom-variant dark (&:where([data-theme=dark], [data-theme=dark] *));
141-
}
142-
</style>
143106
\(head ?? "")
144-
</head>
145-
"""
146-
147-
logger.trace("Rendering content elements")
148-
let contentElements = content.map { $0.render() }.joined()
149-
logger.debug("Document rendered successfully: \(metadata.pageTitle)")
150-
151-
return """
152-
<!DOCTYPE html>
153-
<html lang="\(metadata.locale.rawValue)">
154-
\(headSection)
107+
</head>
155108
<body>
156-
\(contentElements)
109+
\(content.map { $0.render() }.joined())
157110
</body>
158111
</html>
159112
"""

0 commit comments

Comments
 (0)