Skip to content

Commit 6dade4e

Browse files
committed
wip: improve stylesheet
1 parent 9f3182a commit 6dade4e

File tree

6 files changed

+71
-23
lines changed

6 files changed

+71
-23
lines changed

Sources/Pages/HomePage.swift

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public struct HomePage: Page {
3636
body {
3737
header(.class("hero"), .aria.label("About")) {
3838
hgroup {
39+
p(.class("file-name")) { "User.swift" }
3940
h1(.class("hero-title")) { "Erik Bautista Santibanez" }
4041
p(.class("hero-subtitle")) { "Swift & Web Developer" }
4142

@@ -75,6 +76,7 @@ public struct HomePage: Page {
7576
}
7677
main(.v.scope("{ selection: undefined }")) {
7778
header {
79+
p(.class("file-name")) { "Posts.swift" }
7880
hgroup {
7981
h2 { "Posts" }
8082
ul(.class("post-tabs")) {
@@ -86,6 +88,7 @@ public struct HomePage: Page {
8688
}
8789
li {
8890
button(
91+
.class("post-tab"),
8992
.v.on(.click, "selection = \(value)"),
9093
.v.bind("aria-selected", "selection == \(value)"),
9194
.aria.selected(kind == nil)
@@ -103,7 +106,7 @@ public struct HomePage: Page {
103106
.class("post"),
104107
.v.show("!selection || selection == '\(post.kind.rawValue)'")
105108
) {
106-
header { post.dateFormatted }
109+
header(.class("post-date")) { post.dateFormatted }
107110
h3(.class("post-title")) { post.title }
108111
div(.class("post-content")) { post.content }
109112
}
@@ -129,10 +132,16 @@ public struct HomePage: Page {
129132
extension HomePage {
130133
struct Style: @unchecked Sendable, StyleSheet {
131134
var body: some Rule {
132-
// TODO: Add Work-Sans font?
135+
resetStyles()
136+
generalStyles()
137+
heroStyles()
138+
postTabsStyles()
139+
postStyles()
140+
}
133141

134-
// Reset components
135-
":root" => {
142+
/// MARK: - Reset components
143+
@CSSBuilder func resetStyles() -> some Rule {
144+
Pseudo(class: .root) => {
136145
AnyProperty("line-height", "1.5")
137146
}
138147

@@ -149,8 +158,21 @@ extension HomePage {
149158
AnyProperty("display", "block")
150159
AnyProperty("max-inline-size", "100%")
151160
}
161+
}
162+
163+
@CSSBuilder func generalStyles() -> some Rule {
164+
// TODO: Add Work-Sans font?
165+
166+
/// MARK: - General
167+
168+
"@font-face" => {
169+
AnyProperty("font-family", "\"CommitMono\"")
170+
AnyProperty("font-src", "url(\"https://github.com/eigilnikolajsen/commit-mono/raw/ecd81cdbd7f7eb2acaaa2f2f7e1a585676f9beff/src/fonts/fontlab/CommitMonoV143-VF.woff2\")")
171+
AnyProperty("font-style", "normal")
172+
AnyProperty("font-weight", "400")
173+
AnyProperty("font-display", "swap")
174+
}
152175

153-
// General
154176
Pseudo(class: .root) => {
155177
BackgroundColor("#1c1c1c")
156178
Color("#fafafa")
@@ -189,18 +211,32 @@ extension HomePage {
189211
AnyProperty("scale", "calc(100% * -1) 100%")
190212
}
191213

192-
/// Hero header
214+
Class("file-name") => {
215+
Color("#777")
216+
AnyProperty("text-align", "end")
217+
AnyProperty("font-size", "0.85em")
218+
AnyProperty("font-weight", "600")
219+
AnyProperty("font-family", "\"CommitMono\", monospace")
220+
}
221+
222+
Element(.pre) => {
223+
AnyProperty("font-family", "\"CommitMono\", monospace")
224+
}
225+
}
226+
227+
@CSSBuilder func heroStyles() -> some Rule {
228+
/// MARK: - Hero header
193229

194230
Class("hero") => {
195231
AnyProperty("padding-bottom", "1.5rem")
196232
}
197233

198-
Class("hero") * Element(.p) => {
234+
Class("hero-location") => {
199235
Color(.hex("#D0D0D0"))
200236
}
237+
}
201238

202-
/// Post tabs
203-
239+
@CSSBuilder func postTabsStyles() -> some Rule {
204240
Class("post-tabs") => {
205241
AnyProperty("list-style-type", "none")
206242
AnyProperty("margin", "0")
@@ -213,7 +249,7 @@ extension HomePage {
213249
AnyProperty("margin-right", "0.25rem")
214250
}
215251

216-
Class("post-tabs") * Element(.button) => {
252+
Class("post-tab") => {
217253
BackgroundColor("#3c3c3c")
218254
AnyProperty("color", "white")
219255
AnyProperty("border-color", "#505050")
@@ -223,22 +259,24 @@ extension HomePage {
223259
AnyProperty("padding", "0.25rem 0.75rem")
224260
}
225261

226-
Class("post-tabs") * Element(.button) <> .attr("aria-selected", match: .exact, value: "true") => {
262+
Class("post-tab") <> .attr("aria-selected", match: .exact, value: "true") => {
227263
AnyProperty("background-color", "#F0F0F0")
228264
AnyProperty("color", "#101010")
229265
AnyProperty("border-color", "#A0A0A0")
230266
}
267+
}
231268

232-
/// Posts
269+
@CSSBuilder func postStyles() -> some Rule {
270+
/// MARK: - Posts
233271

234272
Class("post") => {
235273
AnyProperty("margin-top", "0.75rem")
236274
AnyProperty("margin-bottom", "1.5rem")
237275
// AnyProperty("border-bottom", "1px dotted #404040")
238276
}
239277

240-
Class("post") > Element(.header) => {
241-
Color(.gray)
278+
Class("post-date") => {
279+
Color("#9A9A9A")
242280
AnyProperty("font-size", "0.75em")
243281
AnyProperty("font-weight", "600")
244282
}
@@ -251,7 +289,6 @@ extension HomePage {
251289
AnyProperty("margin", "revert")
252290
}
253291

254-
/// Code blocks
255292
Class("post") * Element(.pre) => {
256293
AnyProperty("padding", "1rem")
257294
Background("#242424")
@@ -260,6 +297,7 @@ extension HomePage {
260297
AnyProperty("border-width", "1.5px")
261298
AnyProperty("border-radius", "0.75rem")
262299
AnyProperty("overflow-x", "auto")
300+
AnyProperty("font-size", "0.85em")
263301
}
264302
}
265303
}

Sources/Pages/Models/Post+AllCases.swift

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ extension Post: CaseIterable {
99
content: """
1010
Since I started building this website using Swift, I used [elementary](https://github.com/sliemeobn/elementary "link to Swift library") to build \
1111
HTML pages.
12+
13+
```swift
14+
struct CustomSheet: StyleSheet {
15+
var body: some Rule {
16+
Class("books") => {
17+
Color(.red)
18+
BackgroundColor(.red)
19+
}
20+
}
21+
}
22+
```
1223
""",
1324
date: Date(timeIntervalSince1970: 1_738_483_200), // Feb 2, 2025
1425
kind: .project
@@ -17,7 +28,7 @@ extension Post: CaseIterable {
1728
slug: "mochi-released",
1829
title: "Mochi \u{2014} Content Viewer for iOS and macOS",
1930
content: """
20-
TBD
31+
> TBD
2132
""",
2233
date: Date(timeIntervalSince1970: 1_663_225_200), // Sep 15, 2025
2334
kind: .project
@@ -26,7 +37,7 @@ extension Post: CaseIterable {
2637
slug: "anime-now-released",
2738
title: "Anime Now! \u{2014} An iOS and macOS App",
2839
content: """
29-
TBD
40+
> TBD
3041
""",
3142
date: Date(timeIntervalSince1970: 1_663_225_200), // Sep 15, 2025
3243
kind: .project
@@ -35,7 +46,7 @@ extension Post: CaseIterable {
3546
slug: "prism-ui-released",
3647
title: "PrismUI \u{2014} Controlling MSI RGB Keyboard on mac",
3748
content: """
38-
TBD
49+
> TBD
3950
""",
4051
date: Date(timeIntervalSince1970: 1_663_225_200),
4152
kind: .project

Sources/Pages/Models/Post.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Foundation
22

33
struct Post {
44
let slug: String
5-
var hero: Hero?
5+
var header: Header?
66
let title: String
77
let content: HTMLMarkdown
88
let date: Date
@@ -21,7 +21,7 @@ struct Post {
2121
Self.dateCreatedFormatter.string(from: self.date).uppercased()
2222
}
2323

24-
enum Hero {
24+
enum Header {
2525
case link(String)
2626
case image(String)
2727
case video(String)

Sources/Pages/Utils/Elementary+Aria.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ extension HTMLAttribute.aria {
1616
}
1717

1818
static func selected(_ value: Bool?) -> HTMLAttribute {
19-
aria(value?.description)
19+
aria(value.flatMap(String.init))
2020
}
2121

2222
private static func aria(

Sources/Pages/Utils/Elementary+Markdown.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ private struct HTMLMarkdownConverter: MarkupVisitor {
2525
mutating func visitBlockQuote(_ blockQuote: BlockQuote) -> AnyHTML {
2626
let aside = Aside(blockQuote)
2727
blockquote {
28-
strong { aside.kind.displayName }
29-
3028
for child in aside.content {
3129
visit(child)
3230
}

Sources/Pages/Utils/Elementary+Vue.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ struct VueScript: HTML {
1818
const roots = [...document.documentElement.querySelectorAll(`[v-scope]`)]
1919
.filter((root) => !root.matches(`[v-scope] [v-scope]`));
2020
21+
// Similar to how `v-scope` works in `petite-vue`
2122
for (const root of roots) {
2223
const expr = root.getAttribute('v-scope');
2324
root.removeAttribute('v-scope');

0 commit comments

Comments
 (0)