Skip to content

feat!: release version 1.0.0 #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .spi.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PackageDescription

let package = Package(
name: "web-ui",
platforms: [.macOS(.v15), .iOS(.v13), .tvOS(.v13)],
products: [
.library(name: "WebUI", targets: ["WebUI"])
],
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# WebUI

<h2 align="center">
<a href="https://github.com/dec0dOS/amazing-github-template">
<img src="https://github.com/user-attachments/assets/657945a9-5540-4abb-a107-4f6547e4a77e" alt="Logo" width="300">
Expand Down
243 changes: 0 additions & 243 deletions Sources/WebUI/Core/Application.swift

This file was deleted.

81 changes: 17 additions & 64 deletions Sources/WebUI/Core/Document.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ public enum ScriptAttribute: String {
case async
}

public struct Script {
let src: String
let attribute: ScriptAttribute?
}

/// Represents an immutable HTML document with metadata and content.
public struct Document {
private let logger = Logger(label: "com.webui.document")
Expand All @@ -17,7 +22,7 @@ public struct Document {
public var stylesheets: [String]?
public var theme: Theme?
public let head: String?
private let contentBuilder: () -> [any HTML]
public let contentBuilder: () -> [any HTML]

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

var optionalMetaTags: [String] = []
if let image = metadata.image, !image.isEmpty {
logger.trace("Adding og:image meta tag: \(image)")
optionalMetaTags.append(
"<meta property=\"og:image\" content=\"\(image)\">"
)
}
if let author = metadata.author, !author.isEmpty {
logger.trace("Adding author meta tag: \(author)")
optionalMetaTags.append("<meta name=\"author\" content=\"\(author)\">")
}
if let twitter = metadata.twitter, !twitter.isEmpty {
logger.trace("Adding twitter meta tag: \(twitter)")
optionalMetaTags.append(
"<meta name=\"twitter:creator\" content=\"@\(twitter)\">"
)
}
if let keywords = metadata.keywords, !keywords.isEmpty {
logger.trace("Adding keywords meta tag with \(keywords.count) keywords")
optionalMetaTags.append(
"<meta name=\"keywords\" content=\"\(keywords.joined(separator: ", "))\">"
)
}
if let themeColor = metadata.themeColor {
logger.trace("Adding theme-color meta tags")
optionalMetaTags.append(
"<meta name=\"theme-color\" content=\"\(themeColor.light)\" media=\"(prefers-color-scheme: light)\">"
)
optionalMetaTags.append(
"<meta name=\"theme-color\" content=\"\(themeColor.dark)\" media=\"(prefers-color-scheme: dark)\">"
)
}
var optionalTags: [String] = metadata.tags + []
if let scripts = scripts {
logger.trace("Adding \(scripts.count) script tags")
for script in scripts {
optionalMetaTags.append(
optionalTags.append(
"<script \(script.value?.rawValue ?? "") src=\"\(script.key)\"></script>"
)
}
}
if let stylesheets = stylesheets {
logger.trace("Adding \(stylesheets.count) stylesheet links")
for stylesheet in stylesheets {
optionalMetaTags.append(
optionalTags.append(
"<link rel=\"stylesheet\" href=\"\(stylesheet)\">"
)
}
}

logger.trace("Building head section")
let headSection = """
logger.debug("Document rendered successfully: \(metadata.pageTitle)")

return """
<!DOCTYPE html>
<html lang="\(metadata.locale.rawValue)">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>\(metadata.pageTitle)</title>
<meta property="og:title" content="\(metadata.pageTitle)">
<meta name="description" content="\(metadata.description)">
<meta property="og:description" content="\(metadata.description)">
"<meta property=\"og:type\" content=\"\(metadata.type.rawValue)\">"
<meta name="twitter:card" content="summary_large_image">
\(optionalMetaTags.joined(separator: "\n"))
\(optionalTags.joined(separator: "\n"))
<script src="https://unpkg.com/@tailwindcss/browser@4"></script>
<style type="text/tailwindcss">
@theme {
--breakpoint-xs: 30rem;
--breakpoint-3xl: 120rem;
--breakpoint-4xl: 160rem;
\(theme?.generateCSS() ?? "")
@custom-variant dark (&:where([data-theme=dark], [data-theme=dark] *));
}
</style>
\(head ?? "")
</head>
"""

logger.trace("Rendering content elements")
let contentElements = content.map { $0.render() }.joined()
logger.debug("Document rendered successfully: \(metadata.pageTitle)")

return """
<!DOCTYPE html>
<html lang="\(metadata.locale.rawValue)">
\(headSection)
</head>
<body>
\(contentElements)
\(content.map { $0.render() }.joined())
</body>
</html>
"""
Expand Down
Loading
Loading