Files
docs/Sources/Docs/Templates/HomeLink.swift
Michael Housh f05b96e0bf
Some checks failed
CI / release (push) Has been cancelled
feat: Adds dashboard style links to home page.
2025-04-08 09:52:54 -04:00

70 lines
1.5 KiB
Swift

import HTML
struct HomeLink {
let icon: String
let title: String
let description: String
let href: String
let linkType: LinkType
enum LinkType {
case `internal`
case external
}
}
extension HomeLink {
static func `internal`(
_ title: String,
icon: String,
href: String,
description: String
) -> Self {
self.init(icon: icon, title: title, description: description, href: href, linkType: .internal)
}
static func external(
_ title: String,
icon: String,
href: String,
description: String
) -> Self {
self.init(icon: icon, title: title, description: description, href: href, linkType: .external)
}
}
extension HomeLink: NodeConvertible {
func asNode() -> Node {
switch linkType {
case .internal: return internalLink()
case .external: return externalLink()
}
}
private func internalLink() -> Node {
a(class: "bg-orange-400 border-2 border-green-600 p-4 rounded-lg", href: href) {
div(class: "flex text-3xl") {
i(class: "mt-1", customAttributes: ["data-lucide": icon])
p(class: "ps-2") { title }
}
p(class: "text-sm") { description }
}
}
private func externalLink() -> Node {
a(
class: "bg-orange-400 border-2 border-green-600 p-4 rounded-lg",
href: href,
rel: "nofollow",
target: "_blank'"
) {
div(class: "flex text-3xl") {
i(class: "mt-1", customAttributes: ["data-lucide": icon])
p(class: "ps-2") { title }
}
p(class: "text-sm") { description }
}
}
}