Files
docs/Sources/Docs/Templates/HomeLink.swift
Michael Housh a53e808aec
All checks were successful
CI / release (push) Successful in 6m9s
feat: Updates to network article.
2025-04-08 13:36:39 -04:00

76 lines
1.8 KiB
Swift

import HTML
/// Represents homepage link configuration.
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 {
/// Create an internal link (opens in the same tab).
static func `internal`(
_ title: String,
icon: String,
href: String,
description: String
) -> Self {
self.init(icon: icon, title: title, description: description, href: href, linkType: .internal)
}
/// Create an external link (opens in a different tab).
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 [&:hover]:bg-orange-500",
href: href
) {
div(class: "flex text-3xl") {
i(class: "mt-1", customAttributes: ["data-lucide": icon])
span(class: "ps-2") { title }
}
span(class: "text-sm") { description }
}
}
private func externalLink() -> Node {
a(
class: "bg-orange-400 border-2 border-green-600 p-4 rounded-lg [&:hover]:bg-orange-500",
href: href,
rel: "nofollow",
target: "_blank'"
) {
div(class: "flex text-3xl") {
i(class: "mt-1", customAttributes: ["data-lucide": icon])
span(class: "ps-2") { title }
}
span(class: "text-sm") { description }
}
}
}