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>
This commit is contained in:
2026-08-01 10:57:29 +00:00
committed by javier
parent ea00b94841
commit efc933d5d0
8 changed files with 483 additions and 12 deletions
@@ -47,6 +47,56 @@ struct PageTests {
#expect(content.lowerBound < script.lowerBound)
}
@Test
func `omits the summary and canonical tags by default`() {
let html = StubPage().render()
#expect(!html.contains(#"name="description""#))
#expect(!html.contains(#"rel="canonical""#))
}
@Test
func `renders the summary and canonical tags when provided`() {
let html = StubPage(
canonicalURL: "https://stub.example/",
summary: "A stub page."
).render()
#expect(html.contains(#"<meta name="description" content="A stub page.">"#))
#expect(html.contains(#"<link rel="canonical" href="https://stub.example/">"#))
}
@Test
func `omits the social card tags by default`() {
let html = StubPage().render()
#expect(!html.contains(#"property="og:"#))
#expect(!html.contains(#"name="twitter:card""#))
}
@Test
func `renders the social card tags when provided`() {
let html = StubPage(socialCard: .init(
title: "Stub Page",
summary: "A stub page.",
url: "https://stub.example/",
image: .init(
url: "https://stub.example/img/card.png",
width: 2400,
height: 1260
)
)).render()
#expect(html.contains(#"<meta property="og:type" content="website">"#))
#expect(html.contains(#"<meta property="og:title" content="Stub Page">"#))
#expect(html.contains(#"<meta property="og:description" content="A stub page.">"#))
#expect(html.contains(#"<meta property="og:url" content="https://stub.example/">"#))
#expect(html.contains(#"<meta property="og:image" content="https://stub.example/img/card.png">"#))
#expect(html.contains(#"<meta property="og:image:width" content="2400">"#))
#expect(html.contains(#"<meta property="og:image:height" content="1260">"#))
#expect(html.contains(#"<meta name="twitter:card" content="summary_large_image">"#))
}
@Test
func `appends the version token to the asset URLs`() {
let html = StubPage(assetVersion: "0123456789abcdef").render()