Skip to content

Commit f7e1ea1

Browse files
committed
chore: improve vue components
1 parent d6114c2 commit f7e1ea1

File tree

11 files changed

+353
-318
lines changed

11 files changed

+353
-318
lines changed

Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ let package = Package(
99
],
1010
dependencies: [
1111
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.4.0"),
12-
.package(url: "https://github.com/erikbdev/swift-web.git", exact: "0.0.17"),
12+
.package(url: "https://github.com/erikbdev/swift-web.git", exact: "0.2.3"),
1313
.package(url: "https://github.com/hummingbird-project/hummingbird.git", exact: "2.5.0"),
1414
.package(url: "https://github.com/pointfreeco/swift-case-paths.git", from: "1.0.0"),
1515
.package(url: "https://github.com/pointfreeco/swift-url-routing.git", from: "0.6.2"),

Sources/App/SiteMiddleware.swift

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ struct SiteMiddleware<Context: RequestContext>: RouterController {
3535
} operation: {
3636
switch route {
3737
case .home:
38-
return HomePage(codeLang: .resolve(req))
38+
return PageLayout(metadata: .default()) {
39+
HomePage(codeLang: .resolve(req))
40+
}
3941
case .api(.activity(.all)):
4042
do {
4143
return try ActivityClient.Activity.encoder.encode(self.activityClient.redactedActivity(), from: req, context: ctx)
@@ -75,12 +77,27 @@ private struct NotFoundMiddleware<Context: RequestContext>: RouterMiddleware {
7577
throw error
7678
}
7779

78-
return try NotFoundPage(codeLang: .resolve(input))
79-
.response(from: input, context: context, status: .notFound)
80+
return PageLayout(metadata: .default()) {
81+
NotFoundPage(codeLang: .resolve(input))
82+
}
83+
.response(from: input, context: context, status: .notFound)
8084
}
8185
}
8286
}
8387

88+
private extension Metadata {
89+
static func `default`() -> Metadata {
90+
@Dependency(\.publicAssets) var assets
91+
92+
return Metadata(
93+
title: "Erik Bautista Santibanez",
94+
description: "A software developer specialized in mobile and web applications.",
95+
image: assets.assets.og.cardPng.url.assetString,
96+
url: "https://erikb.dev"
97+
)
98+
}
99+
}
100+
84101
extension CodeLang {
85102
fileprivate static func resolve(_ req: Request) -> CodeLang? {
86103
req.uri.queryParameters["codeLang"]

Sources/Pages/Components/Page.swift

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

Sources/Pages/Components/Stylings.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import HTML
22

3-
extension HTML {
3+
extension AsyncHTML {
44
func wrappedStyling() -> HTMLInlineStyle<Self> {
55
self.inlineStyle("border-top", "1px solid #303030")
66
}

Sources/Pages/HomePage.swift

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,24 @@ import HTML
55
import Models
66
import Vue
77

8-
public struct HomePage: Page {
8+
@Vue.Component
9+
public struct HomePage: Page, Sendable {
910
public let title = "Portfolio | Erik Bautista Santibanez"
1011

11-
let initialCodeLang: CodeLang?
12+
@Vue.Reactive let codeLang: CodeLang?
1213

1314
public init(codeLang: CodeLang? = .swift) {
14-
self.initialCodeLang = codeLang
15+
self.codeLang = codeLang
1516
}
1617

17-
public var head: some HTML { EmptyHTML() }
18-
1918
public var body: some HTML {
20-
#VueScope(initialCodeLang) { codeLang in
21-
HeaderView(selected: codeLang)
19+
div {
20+
HeaderView(selected: $codeLang)
2221
main {
2322
Spacer()
24-
UserView(selected: codeLang)
23+
UserView(selected: $codeLang)
2524
Spacer()
26-
PostsView(selected: codeLang)
25+
PostsView(selected: $codeLang)
2726
Spacer()
2827
}
2928
FooterView()
@@ -471,7 +470,7 @@ private struct PostsView: HTML {
471470
}
472471
}
473472

474-
extension HTML {
473+
extension AsyncHTML {
475474
fileprivate func postCodeBlockStyling() -> HTMLInlineStyle<Self> {
476475
self.inlineStyle("padding", "0.75rem", post: " pre")
477476
.inlineStyle("background", "#242424", post: " pre")

Sources/Pages/NotFoundPage.swift

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,22 @@ import Dependencies
22
import HTML
33
import Vue
44

5-
public struct NotFoundPage: Page {
5+
@Vue.Component
6+
public struct NotFoundPage: Page, Sendable {
67
public let title = "404 | Erik Bautista Santibanez"
78

8-
let initialCodeLang: CodeLang?
9+
@Vue.Reactive let codeLang: CodeLang?
910

1011
public init(codeLang: CodeLang? = .swift) {
11-
self.initialCodeLang = codeLang
12-
}
13-
14-
public var head: some HTML {
15-
EmptyHTML()
12+
self.codeLang = codeLang
1613
}
1714

1815
public var body: some HTML {
19-
#VueScope(initialCodeLang) { codeLang in
20-
HeaderView(selected: codeLang)
16+
div {
17+
HeaderView(selected: $codeLang)
2118
Spacer()
2219
main {
23-
InnerView(codeLang: codeLang)
20+
InnerView(codeLang: $codeLang)
2421
}
2522
Spacer()
2623
FooterView()

Sources/Pages/Page.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import HTML
2+
3+
public protocol Page: AsyncHTML, Sendable {
4+
var title: String { get }
5+
}

0 commit comments

Comments
 (0)