From 1033cab2afb1c5bc0eef8fd6b65b7043c3dbf474 Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Mon, 24 Aug 2026 01:40:52 +0200 Subject: [PATCH] Added an optional `founder` reference to the Organization node in the Infrastructure package. --- Packages/Infrastructure/README.md | 9 ++++--- .../Sources/Public/Types/StructuredData.swift | 8 +++++- .../StructuredDataProperty.swift | 2 ++ .../Public/Types/StructuredDataTests.swift | 25 +++++++++++++++++++ 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/Packages/Infrastructure/README.md b/Packages/Infrastructure/README.md index 6be42fc..0ad53b2 100644 --- a/Packages/Infrastructure/README.md +++ b/Packages/Infrastructure/README.md @@ -7,9 +7,9 @@ The shared [Hummingbird](https://github.com/hummingbird-project/hummingbird) too | Routing | `RouterController`, `RouteCollectionBuilder`, the `addController` extension on `RouterMethods` | | Middlewares | `SecurityHeadersMiddleware`, `HTTPSRedirectMiddleware`, `TrailingSlashRedirectMiddleware`, `VaryMiddleware`, `RateLimitMiddleware`, `LocalizationMiddleware`, `NotFoundMiddleware` | | Pages and assets | `Page`, `Asset`, `AssetExtension`, `FingerprintAssets` | -| Link previews | `SocialCard`, its `Image`, and the `Tag` meta tags it derives | -| Structured data | `StructuredData`, the `Node`, `Property`, and `Value` types of its schema.org graph, and the open `Name` and `Kind` vocabularies | -| Analytics | `Analytics`, the tracker script `Attribute`s it derives, and the `origin` its preconnect hint targets | +| Link previews | `SocialCard`, its `Image` and `Style`, and the `Tag` meta tags it derives | +| Structured data | `StructuredData`, the `Node`, `Property`, and `Value` types of its schema.org graph, the open `Name` and `Kind` vocabularies, and the site-wide initializer building the `Organization`/`WebSite` pair | +| Analytics | `Analytics`, the `Event`s a page reports, the tracker script `Attribute`s it derives, and the `origin` its preconnect hint targets | | Responses | `CachedHTMLResponse`, `LocalizedHTMLCollectionResponse` | | Contexts | `LocalizedRequestContext` | | Constants | The `HTTPField.Name` header names, `Int.RateLimit` limits, and `String.Security` header values the middlewares default to | @@ -18,6 +18,7 @@ The shared [Hummingbird](https://github.com/hummingbird-project/hummingbird) too The package holds only what every service can reuse. Anything a service owns is injected, never referenced. - **No site-specific content.** No page markup, no asset catalog, no `Bundle.module` lookups. What a type needs, it takes as a parameter: the `bundle:` whose String Catalog names the supported languages, the `document:` closure that builds a page for a locale, a `Page` conformer's `metadata` and its optional head concerns (`summary`, `canonicalURL`, `socialCard`, `structuredData`, `analytics`). URLs arrive absolute and fully formed — composing them stays with the page. - **Types own their format; `Page` renders generically.** Each head concern derives its own render-ready form — `SocialCard.tags`, `StructuredData.payload`, `Analytics.attributes` — which `Page` applies without knowing the vocabulary. A page's `scripts` and the tracker render as `defer`red head tags, the tracker preceded by a `preconnect` to its cross-origin host. +- **Nodes are joined by `@id`, not repetition.** A node another page must point at gets its identifier from a helper rather than a hand-spelled fragment — `organizationID(forSiteURL:)` names the node the site-wide initializer builds, and that initializer's `founder` takes such an identifier back. A service adds the helper for any node it owns, so neither side can drift. - **Services fill the gaps once, via extensions.** A service restores its convenient call sites retroactively — the Website's `*+Defaults` are the pattern. The open schema.org vocabularies work the same way: the package declares the shared `Property.Name` and `Node.Kind` constants, a service adds its own. - **Method structs.** Single-operation types such as `FingerprintAssets` take lifetime-fixed configuration in `init` and per-call inputs in `callAsFunction`. @@ -28,7 +29,7 @@ Sources/ ├── Public/ public API │ ├── Builders/ RouteCollectionBuilder │ ├── Enumerations/ AssetExtension -│ ├── Extensions/ addController, plus the default header names and values +│ ├── Extensions/ addController, plus the default header names, rate limits, and header values │ ├── Methods/ FingerprintAssets │ ├── Middlewares/ the seven HTTP middlewares │ ├── Protocols/ Asset, LocalizedRequestContext, Page, RouterController diff --git a/Packages/Infrastructure/Sources/Public/Types/StructuredData.swift b/Packages/Infrastructure/Sources/Public/Types/StructuredData.swift index 813be3a..38d0acd 100644 --- a/Packages/Infrastructure/Sources/Public/Types/StructuredData.swift +++ b/Packages/Infrastructure/Sources/Public/Types/StructuredData.swift @@ -66,6 +66,7 @@ public extension StructuredData { /// - email: the address the organization is written to, or `nil` (the default) to omit its property. /// - logo: the absolute URL of the organization's logo, or `nil` (the default) to omit its property. /// - profiles: the absolute URLs of the organization's public profiles, or empty (the default) to omit their property. + /// - founder: the `@id` of the `Person` node founding the organization, or `nil` (the default) to omit its property. init( name: String, url: String, @@ -74,7 +75,8 @@ public extension StructuredData { areaServed: String? = nil, email: String? = nil, logo: String? = nil, - profiles: [String] = [] + profiles: [String] = [], + founder: String? = nil ) { let id = Self.organizationID(forSiteURL: url) @@ -110,6 +112,10 @@ public extension StructuredData { )) } + if let founder { + organization.append(.init(.founder, value: .reference(founder))) + } + self.init(nodes: [ .init( type: .organization, diff --git a/Packages/Infrastructure/Sources/Public/Types/StructuredData/StructuredDataProperty.swift b/Packages/Infrastructure/Sources/Public/Types/StructuredData/StructuredDataProperty.swift index 6600667..b311bdb 100644 --- a/Packages/Infrastructure/Sources/Public/Types/StructuredData/StructuredDataProperty.swift +++ b/Packages/Infrastructure/Sources/Public/Types/StructuredData/StructuredDataProperty.swift @@ -77,6 +77,8 @@ public extension StructuredData.Property.Name { static let description: Self = "description" /// The address the thing a node describes is written to. static let email: Self = "email" + /// The person who founded an organization. + static let founder: Self = "founder" /// The absolute URL of an organization's logo. static let logo: Self = "logo" /// The name of the thing a node describes. diff --git a/Packages/Infrastructure/Tests/Cases/Public/Types/StructuredDataTests.swift b/Packages/Infrastructure/Tests/Cases/Public/Types/StructuredDataTests.swift index 0467739..c2a8603 100644 --- a/Packages/Infrastructure/Tests/Cases/Public/Types/StructuredDataTests.swift +++ b/Packages/Infrastructure/Tests/Cases/Public/Types/StructuredDataTests.swift @@ -46,6 +46,31 @@ struct StructuredDataTests { )) } + @Test + func `references the organization's founder by identifier`() { + let data = StructuredData( + name: "A Site", + url: "https://site.example/", + profiles: ["https://social.example/a-site"], + founder: "https://site.example/who#person" + ) + + // Last of the organization's properties, after the profiles. + #expect(data.payload.contains( + #""sameAs":["https://social.example/a-site"],"founder":{"@id":"https://site.example/who#person"}}"# + )) + } + + @Test + func `omits the founder when the data carries none`() { + let data = StructuredData( + name: "A Site", + url: "https://site.example/" + ) + + #expect(!data.payload.contains("founder")) + } + @Test func `derives the organization's identifier from the site URL`() { let url = "https://site.example/"