Files
ccn/Packages/Infrastructure/Tests/Utils/Pages/StubPage.swift
T
javier efc933d5d0 Extra tags and Social Card integration in the Infrastructure package (#28)
This PR contains the work done to extends the `Page` protocol with the head tags that control search snippets and link previews: a meta description, a canonical URL, and a social card rendered as _Open Graph_ and _Twitter_ meta tags. All three are optional with nil defaults, so existing conformers compile and render unchanged.

Reviewed-on: rock-n-code/loud-amsterdam#28
Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
2026-08-01 10:57:29 +00:00

88 lines
2.3 KiB
Swift

import Elementary
import Foundation
import Infrastructure
/// A ``Page`` with fixed content, metadata, and stub assets.
struct StubPage: Page {
// MARK: Properties
/// The version token appended to the page's asset URLs, or `nil` to leave them unversioned.
let assetVersion: String?
/// The canonical URL rendered in the document head, or `nil` to omit it.
let canonicalURL: String?
/// The locale the page content is localized to.
let locale: Locale
/// The card rendered as link-preview tags in the document head, or `nil` to omit them.
let socialCard: SocialCard?
/// The summary rendered in the document head, or `nil` to omit it.
let summary: String?
// MARK: Initializers
/// Creates a stub page.
/// - Parameters:
/// - locale: the locale the page content is localized to. Defaults to `en`.
/// - assetVersion: the version token appended to the page's asset URLs, or `nil` (the
/// default) to leave them unversioned.
/// - canonicalURL: the canonical URL rendered in the document head, or `nil` (the default)
/// to omit it.
/// - socialCard: the card rendered as link-preview tags in the document head, or `nil`
/// (the default) to omit them.
/// - summary: the summary rendered in the document head, or `nil` (the default)
/// to omit it.
init(
locale: Locale = .init(identifier: "en"),
assetVersion: String? = nil,
canonicalURL: String? = nil,
socialCard: SocialCard? = nil,
summary: String? = nil
) {
self.assetVersion = assetVersion
self.canonicalURL = canonicalURL
self.locale = locale
self.socialCard = socialCard
self.summary = summary
}
// MARK: Computed
var content: some HTML {
p { "Stub content" }
}
var lang: String {
locale.language.languageCode?.identifier ?? "en"
}
var metadata: some HTML {
meta(
.name("stub"),
.content("marker")
)
}
var scripts: [any Asset] {
[StubAsset(
fileExtensions: [.css, .js],
fileName: "stub"
)]
}
var stylesheets: [any Asset] {
[StubAsset(
fileExtensions: [.css, .js],
fileName: "stub"
)]
}
var title: String {
"Stub Page"
}
}