### 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 = "