### Implementing and Registering a Custom Metadata Processor in Swift Source: https://github.com/harlanhaskins/linkpreviewswift/blob/main/README.md Provides an example of creating a custom MetadataProcessor to modify the link preview data, specifically appending the host to the title, and demonstrates how to register this custom processor with the LinkPreviewProvider. ```Swift enum CustomProcessor: MetadataProcessor { static func updateLinkPreview( _ preview: inout LinkPreview, for url: URL, document: Document?, options: MetadataProcessingOptions ) async { let title = preview.title ?? "" if let host = url.host { if !title.isEmpty { title += " • " } title += host } if !title.isEmpty { preview.title = title } } } // Tell the provider to run this processor along with the others. provider.registerProcessor(CustomProcessor.self) let preview = try await provider.load(from: URL(string: "https://example.com")!) print(preview.title) // prints 'Example Domain • example.com' ``` -------------------------------- ### Initializing and Loading Link Previews with LinkPreviewSwift Source: https://github.com/harlanhaskins/linkpreviewswift/blob/main/README.md Demonstrates how to create a LinkPreviewProvider instance, configure its options (like allowAdditionalRequests), and load link previews from a URL (with or without custom headers) or directly from HTML content. ```Swift let provider = LinkPreviewProvider() // Optionally, configure the provider: // Turn off processing that requires making additional requests for more information, // instead choosing only to read data from the single page that's loaded. provider.options.allowAdditionalRequests // Load the preview let preview = try await provider.load(from: url) // You can also provide custom headers to attach to the request let preview = try await provider.load(from: url, headers: [ "Authorization": "Bearer ..." ]) // You can also load directly from HTML let html = "Title" let preview = try await provider.load(html: html, url: URL(string: "example.com")!) ``` -------------------------------- ### Accessing Common Link Preview Metadata in Swift Source: https://github.com/harlanhaskins/linkpreviewswift/blob/main/README.md Illustrates how to access standard OpenGraph metadata properties like image URL, title, and description directly from a loaded LinkPreview object. ```Swift let imageURL = preview.imageURL let title = preview.title let description = preview.description ``` -------------------------------- ### Declaring LinkPreviewSwift Dependency in Swift Package Manager Source: https://github.com/harlanhaskins/linkpreviewswift/blob/main/README.md Provides the necessary code snippet for adding LinkPreviewSwift as a dependency in a Swift Package Manager Package.swift file, specifying the repository URL and branch. ```Swift dependencies: [ .package(url: "https://github.com/harlanhaskins/LinkPreviewSwift.git", branch: "main") ] ``` -------------------------------- ### Reading Custom OpenGraph Properties and Metadata in Swift Source: https://github.com/harlanhaskins/linkpreviewswift/blob/main/README.md Explains how to retrieve custom OpenGraph properties by name using property(named:) and access their content and associated metadata, such as image dimensions. ```Swift // Parses `og:image`, `og:image:width`, and `og:image:height` tags. let imageURLProperty = preview.property(named: "image") let imageURL = imageURLProperty.content if let width = imageURLProperty.metadata["width"], let height = imageURLProperty.metadata["height"] { // Parse size as integers. } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.