57 lines
1.4 KiB
Swift
57 lines
1.4 KiB
Swift
import Foundation
|
|
import HTML
|
|
import Saga
|
|
|
|
/// Displays lists of articles sectioned by a key.
|
|
///
|
|
///
|
|
struct ArticleGrid: NodeConvertible {
|
|
|
|
let articles: [(key: String, value: [Item<ArticleMetadata>])]
|
|
let canocicalURL: String
|
|
let title: String
|
|
let rssLink: String
|
|
let extraHeader: NodeConvertible
|
|
let renderArticle: (Item<ArticleMetadata>) -> Node
|
|
let header: (String) -> Node
|
|
|
|
init(
|
|
articles: [(key: String, value: [Item<ArticleMetadata>])],
|
|
canocicalURL: String,
|
|
title: String,
|
|
rssLink: String,
|
|
extraHeader: any NodeConvertible = Node.fragment([]),
|
|
renderArticle: @escaping (Item<ArticleMetadata>) -> Node = { renderArticleForGrid(article: $0, border: false) },
|
|
header: @escaping (String) -> Node
|
|
) {
|
|
self.articles = articles
|
|
self.canocicalURL = canocicalURL
|
|
self.title = title
|
|
self.rssLink = rssLink
|
|
self.extraHeader = extraHeader
|
|
self.renderArticle = renderArticle
|
|
self.header = header
|
|
}
|
|
|
|
func asNode() -> Node {
|
|
baseLayout(
|
|
canocicalURL: canocicalURL,
|
|
section: .articles,
|
|
title: title,
|
|
rssLink: rssLink,
|
|
extraHeader: extraHeader
|
|
) {
|
|
div(class: "mt-8 mb-10 bg-slate-800 border border-slate-200 rounded-lg") {
|
|
articles.map { key, articles in
|
|
section {
|
|
header(key)
|
|
div(class: "grid gap-10 mx-6 mb-16") {
|
|
articles.map(renderArticle)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|