feat: Unifies article lists to have similar view styles.
All checks were successful
CI / release (push) Successful in 5m36s
All checks were successful
CI / release (push) Successful in 5m36s
This commit is contained in:
56
Sources/Docs/Templates/ArticleGrid.swift
Normal file
56
Sources/Docs/Templates/ArticleGrid.swift
Normal file
@@ -0,0 +1,56 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user