feat: Adds dashboard style links to home page.
Some checks failed
CI / release (push) Has been cancelled
Some checks failed
CI / release (push) Has been cancelled
This commit is contained in:
69
Sources/Docs/Templates/HomeLink.swift
Normal file
69
Sources/Docs/Templates/HomeLink.swift
Normal file
@@ -0,0 +1,69 @@
|
||||
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 }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user