Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/engali94/opengraphkit
OpenGraphKit: A Swift package for parsing OpenGraph metadata from HTML, URLs, and URL requests. Features include cross-platform support
https://github.com/engali94/opengraphkit
Last synced: about 1 month ago
JSON representation
OpenGraphKit: A Swift package for parsing OpenGraph metadata from HTML, URLs, and URL requests. Features include cross-platform support
- Host: GitHub
- URL: https://github.com/engali94/opengraphkit
- Owner: engali94
- Created: 2024-07-16T21:21:38.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-07-17T11:21:28.000Z (5 months ago)
- Last Synced: 2024-10-30T17:27:08.439Z (about 2 months ago)
- Language: Swift
- Homepage:
- Size: 10.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# OpenGraphKit
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2F[yourusername]%2FOpenGraphKit%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/engali94/OpenGraphKit)
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2F[yourusername]%2FOpenGraphKit%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/engali94/OpenGraphKit)
OpenGraphKit is a Swift package that provides an easy way to parse OpenGraph metadata from HTML content, URLs, and URL requests. Compatible with both Apple platforms and Linux.## Features
- Parse OpenGraph metadata from HTML strings
- Fetch and parse OpenGraph metadata from URLs
- Support for custom URL requests
- Asynchronous API using Swift concurrency
- Cross-platform support (Apple platforms and Linux)## Installation
### Swift Package Manager
Add the following to your `Package.swift` file:
```swift
dependencies: [
.package(url: "https://github.com/engali94/OpenGraphKit.git", from: "0.1")
]
```
To integrate OpenGraphKit into your Xcode project using Swift Package Index, follow these steps:1. In Xcode, select "File" → "Add Packages..."
2. Enter the URL: `https://github.com/engali94/OpenGraphKit.git`
3. Select the version rule that fits your needs (e.g., "Up to Next Major" for automatic updates to new versions)
4. Click "Add Package"You can also visit our [Swift Package Index page](https://swiftpackageindex.com/engali94/OpenGraphKit) for more information, alternative integration methods, and to view the generated documentation.
## Usage
All properties are optional, as not all OpenGraph metadata may be present in every page.
### Parsing from HTML
```swift
import OpenGraphKitlet parser = OpenGraphParser()
let html = """Page content
"""
do {
let metadata = try parser.parse(html: html)
print("Title: \(metadata.title ?? "N/A")")
// ... print other metadata properties
} catch {
print("Error: \(error)")
}
```### Parsing from URL
```swift
import OpenGraphKitlet parser = OpenGraphParser()
let url = URL(string: "https://example.com")!do {
let metadata = try await parser.parse(url: url)
print("Title: \(metadata.title ?? "N/A")")
// ... print other metadata properties} catch {
print("Error: \(error)")
}
```### Parsing with Custom URLRequest
```swift
import OpenGraphKitlet parser = OpenGraphParser()
var request = URLRequest(url: URL(string: "https://example.com")!)
do {
let metadata = try await parser.parse(urlRequest: request)
print("Title: \(metadata.title ?? "N/A")")
// ... print other metadata properties
} catch {
print("Error: \(error)")
}
```## Contributing
Contributions to OpenGraphKit are welcome! Please feel free to submit a Pull Request.
## License
OpenGraphKit is released under the MIT license. See LICENSE for details.