Skip to content

feat!: set up static site generation functionality for next-1.0.0 #3

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 2 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
51 changes: 51 additions & 0 deletions Package.resolved

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

10 changes: 5 additions & 5 deletions Sources/WebUI/Core/Metadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public struct ThemeColor {
public struct Metadata {
public var site: String?
public var title: String?
public var titleSeperator: String
public var titleSeperator: String?
public var description: String
public var date: Date?
public var image: String?
Expand All @@ -34,13 +34,13 @@ public struct Metadata {
public var themeColor: ThemeColor?

public var pageTitle: String {
"\(title ?? "")\(titleSeperator)\(site ?? "")"
"\(title ?? "")\(titleSeperator ?? "")\(site ?? "")"
}

public init(
site: String? = nil,
title: String? = nil,
titleSeperator: String = " | ",
titleSeperator: String? = " ",
description: String,
date: Date? = nil,
image: String? = nil,
Expand Down Expand Up @@ -121,9 +121,9 @@ public struct Metadata {
baseTags.append(
"<meta name=\"theme-color\" content=\"\(themeColor.light)\" \(themeColor.dark != nil ? "media=\"(prefers-color-scheme: light)\"" : "")>"
)
if themeColor.dark != nil {
if let themeDark = themeColor.dark {
baseTags.append(
"<meta name=\"theme-color\" content=\"\(themeColor.dark)\" media=\"(prefers-color-scheme: dark)\">"
"<meta name=\"theme-color\" content=\"\(themeDark)\" media=\"(prefers-color-scheme: dark)\">"
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/WebUI/Core/Theme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public struct Theme {
--breakpoint-xs: 30rem;
--breakpoint-3xl: 120rem;
--breakpoint-4xl: 160rem;
\(self.generateCSS() ?? "")
\(self.generateCSS())
@custom-variant dark (&:where([data-theme=dark], [data-theme=dark] *));
}
"""
Expand Down
6 changes: 3 additions & 3 deletions Tests/WebUITests/Core/ApplicationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Testing
@Suite("Application Tests") struct ApplicationTests {
@Test("Creates the build directory and populates correctly")
func createsAndPopulatesBuildDirectory() throws {
let app = Application(
let app = Website(
routes: [
Document(
path: "index",
Expand All @@ -22,7 +22,7 @@ import Testing
}
Main {
Stack {
Heading(level: .one) { "Tagline" }
Heading(.one) { "Tagline" }
Text { "Lorem ipsum dolor sit amet." }
}
}
Expand All @@ -35,7 +35,7 @@ import Testing
metadata: .init(title: "About", description: "Learn more here")
) {
Article {
Heading(level: .two) { "Article Heading" }
Heading(.two) { "Article Heading" }
Text { "Lorem ipsum dolor sit amet." }
}
},
Expand Down
5 changes: 3 additions & 2 deletions Tests/WebUITests/Core/DocumentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Testing
metadata: Metadata(
site: "Test Site",
title: "Hello World",
titleSeperator: " | ",
description: "A test description"
)
) {
Expand Down Expand Up @@ -40,7 +41,7 @@ import Testing
metadata: Metadata(
site: "Test Site",
title: "Full Test",
titleSeperator: "-",
titleSeperator: " - ",
description: "A complete metadata test",
date: Date(),
image: "https://example.com/image.png",
Expand All @@ -49,7 +50,7 @@ import Testing
twitter: "testhandle",
locale: .ru,
type: .article,
themeColor: .init(light: "#0099ff", dark: "#1c1c1c"),
themeColor: .init("#0099ff", dark: "#1c1c1c"),
)
) {
"Content"
Expand Down
12 changes: 7 additions & 5 deletions Tests/WebUITests/Core/MetadataTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ struct MetadataTests {
let metadata = Metadata(
site: "Test Site",
title: "Test Title",
titleSeperator: " | ",
description: "Test description",
themeColor: .init(light: "#0099ff", dark: "#1c1c1c")
themeColor: .init("#0099ff", dark: "#1c1c1c")
)

// Assert
#expect(metadata.site == "Test Site")
#expect(metadata.title == "Test Title")
#expect(metadata.description == "Test description")
#expect(metadata.titleSeperator == "|")
#expect(metadata.titleSeperator == " | ")
#expect(metadata.pageTitle == "Test Title | Test Site")
#expect(metadata.locale == .en)
#expect(metadata.themeColor?.light == "#0099ff")
Expand All @@ -30,6 +31,7 @@ struct MetadataTests {
@Test func testNoSiteMetadata() throws {
let metadata = Metadata(
title: "Just Title",
titleSeperator: nil,
description: "No site metadata"
)

Expand All @@ -42,11 +44,11 @@ struct MetadataTests {
let metadata = Metadata(
site: "My Site",
title: "My Title",
titleSeperator: "-",
titleSeperator: " - ",
description: "Custom separator test"
)

#expect(metadata.titleSeperator == "-")
#expect(metadata.titleSeperator == " - ")
#expect(metadata.pageTitle == "My Title - My Site")
}

Expand All @@ -58,7 +60,7 @@ struct MetadataTests {
let metadata = Metadata(
site: "Full Site",
title: "Full Title",
titleSeperator: ":",
titleSeperator: " : ",
description: "Full metadata description",
date: testDate,
image: "/images/test.jpg",
Expand Down
18 changes: 9 additions & 9 deletions Tests/WebUITests/ElementTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,9 @@ import Testing

@Test("Heading element")
func testHeadingElement() async throws {
let heading1 = Heading(level: .one) { "Main Title" }
let heading2 = Heading(level: .two) { "Subtitle" }
let heading6 = Heading(level: .six) { "Small Heading" }
let heading1 = Heading(.one) { "Main Title" }
let heading2 = Heading(.two) { "Subtitle" }
let heading6 = Heading(.six) { "Small Heading" }

#expect(heading1.render() == "<h1>Main Title</h1>")
#expect(heading2.render() == "<h2>Subtitle</h2>")
Expand Down Expand Up @@ -484,7 +484,7 @@ import Testing
@Test("Header element")
func testHeaderElement() async throws {
let header = Header(id: "page-header") {
Heading(level: .one) { "Site Title" }
Heading(.one) { "Site Title" }
}

let rendered = header.render()
Expand Down Expand Up @@ -551,7 +551,7 @@ import Testing
@Test("Article element")
func testArticleElement() async throws {
let article = Article(id: "blog-post") {
Heading(level: .two) { "Article Title" }
Heading(.two) { "Article Title" }
Text { "Article content" }
}

Expand All @@ -566,7 +566,7 @@ import Testing
@Test("Section element")
func testSectionElement() async throws {
let section = Section(id: "features") {
Heading(level: .three) { "Features" }
Heading(.three) { "Features" }
Text { "Feature list" }
}

Expand Down Expand Up @@ -649,7 +649,7 @@ import Testing
func testPageLayout() async throws {
let page = Fragment {
Header(id: "main-header") {
Heading(level: .one) { "My Website" }
Heading(.one) { "My Website" }
Navigation {
List(type: .unordered, classes: ["nav-links"]) {
Item { Link(to: "/") { "Home" } }
Expand All @@ -660,12 +660,12 @@ import Testing
}
Main {
Article {
Heading(level: .two) { "Welcome" }
Heading(.two) { "Welcome" }
Text { "This is the main content of the page." }
}
}
Aside(id: "sidebar") {
Heading(level: .three) { "Related Links" }
Heading(.three) { "Related Links" }
List(type: .unordered) {
Item { Link(to: "/link1") { "Link 1" } }
Item { Link(to: "/link2") { "Link 2" } }
Expand Down