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 structured data rendered as a JSON-LD script in the document head, or `nil` to omit it. let structuredData: StructuredData? /// 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. /// - structuredData: the structured data rendered as a JSON-LD script in the document /// head, or `nil` (the default) to omit it. /// - 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, structuredData: StructuredData? = nil, summary: String? = nil ) { self.assetVersion = assetVersion self.canonicalURL = canonicalURL self.locale = locale self.socialCard = socialCard self.structuredData = structuredData 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" } }