{"id":17211056,"url":"https://github.com/zadr/og","last_synced_at":"2025-04-13T22:32:16.447Z","repository":{"id":62449291,"uuid":"62524526","full_name":"zadr/OG","owner":"zadr","description":"An OpenGraph (Link Preview) parser in Swift","archived":false,"fork":false,"pushed_at":"2022-03-24T01:52:08.000Z","size":54,"stargazers_count":56,"open_issues_count":5,"forks_count":4,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-11T22:17:54.751Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zadr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-04T02:01:17.000Z","updated_at":"2025-02-27T05:18:07.000Z","dependencies_parsed_at":"2022-11-01T23:18:07.350Z","dependency_job_id":null,"html_url":"https://github.com/zadr/OG","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zadr%2FOG","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zadr%2FOG/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zadr%2FOG/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zadr%2FOG/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zadr","download_url":"https://codeload.github.com/zadr/OG/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248790695,"owners_count":21162073,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-15T02:56:07.741Z","updated_at":"2025-04-13T22:32:16.042Z","avatar_url":"https://github.com/zadr.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"What is this?\n=====\n\nOG is an [OpenGraph](https://ogp.me) parser in Swift.\n\nWhat's OpenGraph?\n=====\nYou know the smart previews of websites that appear on Facebook or Twitter? OpenGraph is the spec's used to help make that happen.\n\nApple, recognizing that `OpenGraph` isn't the friendliest term, calls these previews [Link Previews](https://developer.apple.com/library/content/technotes/tn2444/_index.html). Hey, searchbot indexer, OG is a Link Preview Parser.\n\nWhat's in this?\n=====\n\nIncluded is an Xcode Workspace containing an Xcodeproj for a dynamic library and an Xcode Playground to experiment with. \n\nWhat do I need to use this?\n=====\n\nRequirements include iOS 8, Mac OS X 10.9, tvOS 9.0 or watchOS 2.0 and Swift 3.0 (included with Xcode 8.x) or Swift 4.0 (Included with Xcode 9.x).\n\nWhat do I do to start using this?\n=====\n\nTo start using OG, you can add it to your project by:\n- Using [Carthage](https://github.com/Carthage/Carthage) and adding `github \"zadr/OG\" ~\u003e 1.3.3` to your `Cartfile`.\n- Using [CocoaPods](https://cocoapods.org) by adding `pod 'OG', '~1.3.3` to your `Podfile`.\n- Adding the current repository as a [git submodule](https://git-scm.com/docs/git-submodule), adding `OG.xcodeproj` into your `xcodeproj`, and adding `OG.framework` as an embedded binary to the Target of your project.\n\nWhat if I need help or want to help?\n=====\n\nIf you need any help, or find a bug, please [open an issue](https://github.com/zadr/OG/issues)! If you'd like to fix a bug or make any other contribution, feel free to open an issue, [make a pull request](https://github.com/zadr/OG/pulls), or [update the wiki](https://github.com/zadr/OG/wiki) with anything that you found helpful.\n\nWhat does using this look like?\n=====\n\nThere are two ways of using OG.\n\nThe first way is to fetch metadata from a `URL` (or a `URLRequest`) automatically:\n\n```swift\nif let url = URL(string: \"https://…\") {\n\turl.fetchOpenGraphData { (metadata) in\n\t\tprint(metadata)\n\t}\n}\n```\n\nAnd the second way is more hands on; instead of fetching, parsing, and tracking tags automatically, OG exposes the components used for each step so you can pick and choose as needed.\n\n```swift\n// first, fetch data from the network\nif let url = URL(string: \"https://…\") {\n\t// first fetch html that might have opengraph previews\n\t// The demo uses the built-in `URLSession`, but anything that can fetch data can be used here \n\tlet task = URLSession.shared.dataTask(with: url) { (data, response, error)\n\t\t// make sure we successfully completed a request\n\t\tif let response = response as? HTTPURLResponse, response.statusCode \u003e= 200, response.statusCode \u003c 300 {\n\t\t\tif let data = data, let html = String(data: data, encoding: .utf8) {\n\t\t\t\tparse(html: html)\n\t\t\t}\n\t\t}\n\t}\n\n\ttask.resume()\n}\n```\n\n\n```swift\n// and then parse OpenGraph meta tags out of an html document\nfunc parse(html: String) {\n\t// then create a parser that can tell us the contents of each html tag and any associated key/value properties it has\n\t// `Parser` is provided, but this can be substituted with anything else that can iterate through html tags \n\tlet parser = Parser()\n\n\t// and keep track of each \u003cmeta class=\"og:…\"\u003e tag as the parser encounters it\n\t// This could also be replaced with another component, but outside of testing purposes, there's less of an obvious need to do so than with the other steps of the process.\n\tlet tagTracker = TagTracker()\n\tparser.onFind = { (tag, values) in\n\t\tif !tagTracker.track(tag, values: values) {\n\t\t\tprint(\"refusing to track non-meta tag \\(tag) with values \\(values)\")\n\t\t}\n\t}\n\n\tif parser.parse(html) {\n\t\t// - If we can parse html, map over our results to go from arrays of arrays of dictionaries (`[[String: OpenGraphType]]`)\n\t\t// to an array of OpenGraph objects.\n\t\t// - Note: OpenGraph can have multiple elements on a page (for example, an og:article, follwed by an og:author, followed by another og:author)\n\t\tlet tags = tagTracker.metadatum.map(Metadata.from)\n\t\tprint(tags)\n\t}\n}\n```\n\nWhat do I do after that?\n=====\nProbably, put a preview of the website on screen. To help with this, every OpenGraph `Metadata` object has a `title`, an `imageUrl`, and a `url` of what to open upon tap or click.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzadr%2Fog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzadr%2Fog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzadr%2Fog/lists"}