Skip to content

Commit 6bf7c59

Browse files
committed
fix: switch codeLang for NotFoundPage
1 parent f06dca1 commit 6bf7c59

File tree

8 files changed

+78
-27
lines changed

8 files changed

+78
-27
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.13"),
12+
.package(url: "https://github.com/erikbdev/swift-web.git", exact: "0.0.15"),
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/Pages/Components/FooterView.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ struct FooterView: HTML {
2424
}
2525
.containerStyling()
2626
.inlineStyle("padding", "1rem 1.5rem")
27+
.inlineStyle("height", "100%")
2728
}
2829
.inlineStyle("text-align", "center")
30+
.inlineStyle("flex-grow", "1")
2931
.wrappedStyling()
3032
}
3133
}

Sources/Pages/Components/HeaderView.swift

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import HTML
44
import Vue
55

66
struct HeaderView: HTML {
7-
@Dependency(\.envVars) var envVars
7+
let selected: Vue.Expression
88

99
var body: some HTML {
1010
header {
@@ -16,9 +16,8 @@ struct HeaderView: HTML {
1616
.inlineStyle("font-weight", "bold")
1717
}
1818
.inlineStyle("text-decoration", "none")
19-
// TODO: Add buttons to allow switching between code styling or plain text
2019

21-
CodeSelector()
20+
CodeSelector(selected: selected)
2221
}
2322
.containerStyling()
2423
.inlineStyle("display", "flex")
@@ -31,12 +30,15 @@ struct HeaderView: HTML {
3130
}
3231
}
3332

34-
private struct CodeSelector: VueComponent {
35-
@Reactive let visible = false
33+
private struct CodeSelector: HTML {
34+
let selected: Vue.Expression
3635

3736
var body: some HTML {
38-
div {
39-
button(.v.on(.click, Expression(rawValue: "\($visible) = \(!$visible)"))) {
37+
#VueScope(false) { (visible: Vue.Expression) in
38+
button(
39+
.v.on(.click, visible.assign(!visible)),
40+
.v.bind(attrOrProp: "style", Expression(rawValue: "\(visible) ? { background: '#8A8A8A', color: '#080808' } : null"))
41+
) {
4042
code { "</>" }
4143
}
4244
.inlineStyle("font-weight", "bold")
@@ -46,19 +48,26 @@ private struct CodeSelector: VueComponent {
4648
.inlineStyle("border-radius", "0.3rem")
4749
.inlineStyle("padding", "0.28rem 0.4rem")
4850
.inlineStyle("color", "#AAA")
51+
.inlineStyle("pointer", "cursor")
4952

50-
ul(.v.show($visible)) {
53+
ul(.hidden, .v.bind(attrOrProp: "hidden", !visible)) {
5154
for code in CodeLang.allCases {
5255
li {
53-
button(.v.on(.click, Expression(rawValue: "\($visible) = null"))) {
56+
button(
57+
.v.on(.click, selected.assign(Expression(code))),
58+
.v.on(.click, modifiers: .prevent, visible.assign(!visible))
59+
) {
5460
code.title
5561
}
5662
.inlineStyle("all", "unset")
5763
.inlineStyle("display", "inline-block")
5864
.inlineStyle("width", "100%")
5965
.inlineStyle("padding", "0.5rem")
6066
.inlineStyle("cursor", "pointer")
67+
// TODO: Add background highlight
68+
// .inlineStyle("background", "#2A2A2A", pseudo: .hover)
6169
}
70+
.inlineStyle("overflow", "hidden")
6271
}
6372
}
6473
.inlineStyle("position", "absolute")

Sources/Pages/Components/Page.swift

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ extension Page {
2424
withDependencies {
2525
$0.ssg = .class
2626
} operation: {
27-
VueDocument._render(
28-
VueDocument(
27+
BaseLayout._render(
28+
BaseLayout(
2929
head: {
3030
meta(.charset(.utf8))
3131
tag("title") { document.title }
@@ -44,10 +44,12 @@ extension Page {
4444
}
4545
html {
4646
line-height: 1.5;
47+
height: 100%;
4748
}
4849
body {
4950
background-color: #1c1c1c;
5051
color: #fafafa;
52+
height: 100%;
5153
}
5254
pre a {
5355
text-decoration: none;
@@ -68,6 +70,9 @@ extension Page {
6870
font-feature-settings: "ss03", "ss04", "ss05";
6971
line-height: 1;
7072
}
73+
[v-cloak] {
74+
display: none;
75+
}
7176
"""
7277
}
7378
/// Xcode Styling
@@ -79,15 +84,19 @@ extension Page {
7984
.defer
8085
)
8186
script(
82-
.src("https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/swift.min.js"),
87+
.src(
88+
"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/swift.min.js"),
8389
.defer
8490
)
8591
script(
86-
.src("https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/rust.min.js"),
92+
.src(
93+
"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/rust.min.js"),
8794
.defer
8895
)
8996
script(
90-
.src("https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/javascript.min.js"),
97+
.src(
98+
"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/javascript.min.js"
99+
),
91100
.defer
92101
)
93102
script(
@@ -107,6 +116,13 @@ extension Page {
107116
.inlineStyle("font-size", "0.8em", media: .minWidth(390))
108117
.inlineStyle("font-size", "0.9em", media: .minWidth(480))
109118
.attribute("lang", value: document.lang)
119+
120+
script(.type(.module), .defer) {
121+
"""
122+
import { createApp } from "https://unpkg.com/petite-vue@0.4.1/dist/petite-vue.es.js";
123+
createApp().mount();
124+
"""
125+
}
110126
}
111127
),
112128
into: &output
@@ -118,4 +134,12 @@ extension Page {
118134
private struct BaseLayout<Head: HTML, Body: HTML>: HTMLDocument {
119135
var head: Head
120136
var body: Body
137+
138+
init(
139+
@HTMLBuilder head: () -> Head,
140+
@HTMLBuilder body: () -> Body
141+
) {
142+
self.head = head()
143+
self.body = body()
144+
}
121145
}

Sources/Pages/HomePage.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public struct HomePage: Page {
1818
public var head: some HTML { EmptyHTML() }
1919

2020
public var body: some HTML {
21-
div(.v.scope([:])) {
22-
HeaderView()
21+
#VueScope(CodeLang.swift) { (selected: Vue.Expression) in
22+
HeaderView(selected: selected)
2323
Spacer()
2424
main {
2525
UserView()

Sources/Pages/Models/CodeLang.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
enum CodeLang: String, CaseIterable {
1+
enum CodeLang: String, CaseIterable, Encodable {
22
case swift
33
case rust
44
case typescript

Sources/Pages/NotFoundPage.swift

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import HTML
2+
import Vue
23

34
public struct NotFoundPage: Page {
45
public let title = "Erik Bautista Santibanez | Not Found"
@@ -11,14 +12,14 @@ public struct NotFoundPage: Page {
1112
}
1213

1314
public var body: some HTML {
14-
div {
15-
HeaderView()
15+
#VueScope(CodeLang.swift) { (selected: Vue.Expression) in
16+
HeaderView(selected: selected)
1617
Spacer()
1718
main {
1819
section {
1920
div {
2021
div {
21-
Heading()
22+
Heading(selected: selected)
2223
}
2324
}
2425
.containerStyling()
@@ -35,9 +36,14 @@ public struct NotFoundPage: Page {
3536
Spacer()
3637
FooterView()
3738
}
39+
.inlineStyle("display", "flex")
40+
.inlineStyle("flex-direction", "column")
41+
.inlineStyle("height", "100%")
3842
}
3943

4044
private struct Heading: HTML {
45+
let selected: Vue.Expression
46+
4147
var body: some HTML {
4248
pre {
4349
code { "// 404 ERROR" }
@@ -50,13 +56,23 @@ public struct NotFoundPage: Page {
5056
.inlineStyle("margin-bottom", "0.5rem")
5157

5258
pre {
53-
code(.class("hljs language-swift")) {
59+
code(.v.cloak, .v.if(selected == Expression(CodeLang.rust)), .class("hljs language-rust")) {
5460
"""
55-
throw Error.pageNotFound
61+
panic!("page not found")
62+
"""
63+
}
64+
code(.v.cloak, .v.elseIf(selected == Expression(CodeLang.typescript)), .class("hljs language-typescript")) {
65+
"""
66+
throw new Error("page not found")
5667
"""
5768
}
58-
.inlineStyle("font-size", "0.9em")
69+
code(.v.else, .class("hljs language-swift")) {
70+
"""
71+
throw Error.pageNotFound
72+
"""
73+
}
5974
}
75+
.inlineStyle("font-size", "0.9em")
6076
}
6177
}
6278
}

0 commit comments

Comments
 (0)