{"id":19216301,"url":"https://github.com/huangrunhua/linkpreview","last_synced_at":"2025-04-10T18:41:51.387Z","repository":{"id":154219890,"uuid":"629918209","full_name":"HuangRunHua/LinkPreview","owner":"HuangRunHua","description":"Preview Links Like Twitter Did | Totally SwiftUI | Example","archived":false,"fork":false,"pushed_at":"2023-04-26T09:26:38.000Z","size":1707,"stargazers_count":13,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T16:21:16.059Z","etag":null,"topics":["link-preview","swift","swiftui","twitter"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HuangRunHua.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-19T09:37:49.000Z","updated_at":"2024-08-28T16:47:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"08c08928-f9a7-49a5-8a87-7d8c831b6058","html_url":"https://github.com/HuangRunHua/LinkPreview","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HuangRunHua%2FLinkPreview","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HuangRunHua%2FLinkPreview/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HuangRunHua%2FLinkPreview/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HuangRunHua%2FLinkPreview/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HuangRunHua","download_url":"https://codeload.github.com/HuangRunHua/LinkPreview/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248271909,"owners_count":21075800,"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":["link-preview","swift","swiftui","twitter"],"created_at":"2024-11-09T14:16:37.021Z","updated_at":"2025-04-10T18:41:51.368Z","avatar_url":"https://github.com/HuangRunHua.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LinkPreview\nThis small project shows how to embed links to your own SwiftUI project. You can use this package directly and with just a few lines of code you can achieve the same effect just like Twitter.\n\n![](https://github.com/HuangRunHua/LinkPreview/raw/main/Cover.JPEG)\n\n## System Requirements\n\n- Xcode 14.0+\n- iOS \u0026 iPadOS 15.0+\n\n## Understand A LinkPreviewView\n\nA `LinkPreviewView` will display metadata from a specific URL, the metadata is shown below:\n\n```html\n\u003cmeta property=\"og:title\" content=\"Large, creative AI models will transform lives and labour markets\"\u003e\n\u003cmeta property=\"og:image\" content=\"https://www.economist.com/interactive/science-and-technology/2023/04/22/large-creative-ai-models-will-transform-how-we-live-and-work/promo.jpg\"\u003e\n\u003cmeta property=\"og:description\" content=\"They bring enormous promise and peril. In the first of three special articles we explain how they work\"\u003e\n```\n\nThe above content (title, image, description) will be parsed and shown just as the picture shows above.\n\nThere is also a property called `publisher` in a `LinkPreviewView`. I defined the `publisher` to be the main link for example the `publisher` of a link `https://www.economist.com/interactive/science-and-technology/2023/04/22/large-creative-ai-models-will-transform-how-we-live-and-work?fsrc=core-app-economist` will be `economist.com` and the  `publisher` of a link `https://github.io/xxxxx` will be `github.io`.\n\n\u003e Noted that if a web page does not contain the metadata above then the publisher will be the only element to be shown inside a `LinkPreviewView`.\n\n### YouTube Video Support\nIf your link points to [YouTube](httpe://youtube.com) and to be able to show correctly using this framework, please check the link contains `=`, for example, the following link is valid:\n\n```bash\nhttps://www.youtube.com/watch?v=ANn9ibNo9SQ\n```\n\nBehind the `=` is your video ID, make sure there is noly one `=` and your video ID is just behind the `=`.\n\n## How to Use\n\nSince this project is now not a Swift package, you coud just drag the `LinkPreviewView.swift` , `LinkDataFetcher.swift` and do not forget the color defined inside the `ColorExtension.swift` and `Assets` to your project.\n\n### Define A LinkDataFetcher Object\n\nFirst, you have to define a `LinkDataFetcher` object just shows in the following way:\n\n```swift\nldf = LinkDataFetcher(\n  link: \"https://www.economist.com/special-report/2023/04/14/all-change\"\n)\n```\n\nA `LinkDataFetcher` object receives only a link string.\n\n### Embed LinkPreviewView to Your Project\n\nThen you can embed a `LinkPreviewView` to your project:\n\n```swift\nLinkPreviewView(linkDataFetcher: ldf, tapAction: tapAction(link:publisher:linkTitle:linkDescription:linkImage:))\n```\n\n`tapAction` decides what action should be implemented when someone tap the link view. You can also write in the following way:\n\n```swift\nLinkPreviewView(linkDataFetcher: ldf) { link, publisher, linkTitle, linkDescription, linkImage in\n\tif let linkDescription {\n\t\tprint(linkDescription)\n\t}\n}\n```\n\n## Websites That Support\nHere is the list that shows which website supports in `LinkPreview`. Noted that not all websites are test.\n\n- [x] [Twitter](https://twitter.com)\n- [x] [YouTube](https://youtube.com)\n- [x] [The Economist](https://www.economist.com)\n- [x] [New Scientist](https://www.newscientist.com)\n- [x] [GitHub](https://github.com)\n- [x] [Apple](https://www.apple.com)\n- [x] [The New Yorker](https://www.newyorker.com)\n- [x] [The New York Times](https://www.nytimes.com/)\n- [x] [TIME](https://time.com/)(Picture may not show)\n- [x] [Bloomberg](https://www.bloomberg.com)\n- [x] [WIRED](https://www.wired.com)\n- [x] [Nature](https://www.nature.com/)\n- [x] [Science](https://www.science.org/)\n- [x] [BBC](https://www.bbc.com/)\n- [x] [CNN](https://www.cnn.com)\n- [x] [The Guardian](https://www.theguardian.com)\n- [x] [The Atlantic](https://www.theatlantic.com)\n- [x] [Reuters](https://www.reuters.com/)\n- [x] [The Los Angeles Times](https://www.latimes.com)\n- [x] [Washington Post](https://www.washingtonpost.com)\n- [x] [The Wall Street Journal](https://www.wsj.com)\n- [x] [The New York Daily News](https://www.nydailynews.com)\n- [x] [New York Post](https://nypost.com)\n- [x] [Chicago Tribune](https://www.chicagotribune.com)\n- [x] [NewsWeek](https://www.newsweek.com)\n- [x] [Fortune](https://fortune.com)\n- [x] [微信读书](https://weread.qq.com)\n- [x] [AP News](https://apnews.com)\n- [x] [Fox News](https://www.foxnews.com)\n- [x] [NBC News](https://www.nbcnews.com)\n- [x] [9to5Mac](https://9to5mac.com/)\n- [x] [Vox](https://www.vox.com)\n- [x] [Yahoo! News](https://news.yahoo.com/)\n- [x] [POLITICO](https://www.politico.eu/)\n- [ ] [NPR News](https://www.npr.org)\n- [ ] [Financial Times](https://www.ft.com/)\n- [ ] [USA Today](https://www.usatoday.com/)\n- [ ] [Reader's Digest](https://www.rd.com)\n- [ ] [The Times](https://www.thetimes.co.uk)\n\n## Last But Not Least\nYou can make contributions too.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuangrunhua%2Flinkpreview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhuangrunhua%2Flinkpreview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuangrunhua%2Flinkpreview/lists"}