127 lines
3.1 KiB
Swift
127 lines
3.1 KiB
Swift
import HTML
|
||
import Saga
|
||
|
||
func renderPage(context: ItemRenderingContext<PageMetadata>) -> Node {
|
||
let section = Section(rawValue: context.item.metadata.section ?? "")
|
||
assert(section != nil)
|
||
|
||
return baseLayout(
|
||
canocicalURL: context.item.url,
|
||
section: section!,
|
||
title: context.item.title,
|
||
extraHeader: section == .home ? generateHeader(.home) : Node.fragment([])
|
||
) {
|
||
switch section {
|
||
case .home:
|
||
renderHome(body: context.item.body)
|
||
case .notFound:
|
||
let articles = context.allItems
|
||
.compactMap { $0 as? Item<ArticleMetadata> }
|
||
.prefix(10)
|
||
render404(body: context.item.body, articles: Array(articles))
|
||
default:
|
||
renderNonHome(body: context.item.body)
|
||
}
|
||
}
|
||
}
|
||
|
||
func renderHome(body: String) -> Node {
|
||
div {
|
||
div(class: "my-24 font-avenir leading-[1.25] font-thin text-center [&>h1>strong]:font-bold") {
|
||
Node.raw(body)
|
||
}
|
||
div {
|
||
h2 { "Quick Links" }
|
||
div(class: "grid lg:grid-cols-2 gap-6") {
|
||
HomeLink.internal(
|
||
"Articles",
|
||
icon: "newspaper",
|
||
href: "/articles/",
|
||
description: "Click here to view all articles."
|
||
)
|
||
|
||
HomeLink.external(
|
||
"Purchase Orders",
|
||
icon: "calculator",
|
||
href: "https://po.housh.dev",
|
||
description: "Purchase orders application."
|
||
)
|
||
|
||
HomeLink.external(
|
||
"Service Monitor",
|
||
icon: "heart-pulse",
|
||
href: "https://uptime.housh.dev/status/housh-dev",
|
||
description: "Server and services uptime status page."
|
||
)
|
||
|
||
HomeLink.external(
|
||
"Unifi Console",
|
||
icon: "earth",
|
||
href: "https://unifi.ui.com",
|
||
description: "Network management."
|
||
)
|
||
|
||
HomeLink.external(
|
||
"Excalidraw",
|
||
icon: "pen-tool",
|
||
href: "https://draw.housh.dev",
|
||
description: "A drawing utility that runs locally in your browser."
|
||
)
|
||
|
||
HomeLink.external(
|
||
"Gitea",
|
||
icon: "git-branch",
|
||
href: "https://git.housh.dev/explore/repos",
|
||
description: "Explore source code."
|
||
)
|
||
|
||
HomeLink.external(
|
||
"Legacy Purchase Orders",
|
||
icon: "file-archive",
|
||
href: "https://legach-po.housh.dev",
|
||
description: "Legacy purchase order application (pre-2025)."
|
||
)
|
||
|
||
HomeLink.external(
|
||
"HVAC Toolbox",
|
||
icon: "hammer",
|
||
href: "https://hvac-toolbox.com",
|
||
description: "A collection of HVAC calculators."
|
||
)
|
||
}
|
||
}
|
||
script(src: "https://unpkg.com/lucide@latest")
|
||
Node.raw("""
|
||
<script>
|
||
lucide.createIcons();
|
||
</script>
|
||
""")
|
||
}
|
||
}
|
||
|
||
func renderNonHome(body: String) -> Node {
|
||
article {
|
||
div(class: "font-avenir") {
|
||
Node.raw(body)
|
||
}
|
||
}
|
||
}
|
||
|
||
func render404(body: String, articles: [Item<ArticleMetadata>]) -> Node {
|
||
article(class: "prose") {
|
||
Node.raw(body)
|
||
|
||
ul {
|
||
articles.map { article in
|
||
li {
|
||
a(href: article.url) { article.title }
|
||
}
|
||
}
|
||
}
|
||
|
||
div {
|
||
a(href: "/articles/") { "› See all articles" }
|
||
}
|
||
}
|
||
}
|