ios-osushi / website

iOS OsushiのWebサイトのソースです。
https://ios-osushi.github.io/
31 stars 4 forks source link

URLをOGPカード表示したい #18

Open uhooi opened 2 years ago

uhooi commented 2 years ago

概要

URL を OGP カード表示したい。

uhooi commented 2 years ago

OG データをダウンロードして、自前でレンダリングする必要があるかも。 その場合は OpenGraphDataDownloader が使えそう。 ref: https://github.com/marty-suzuki/URLEmbeddedView#opengraphdatadownloader

uhooi commented 2 years ago

CSS が得意じゃないから、自前でレンダリングは少し厳しい、、 OG カード表示の CSS がオープンソースであればいいんだけど、、

treastrain commented 2 years ago

macOS インスタンスを使うとすれば、LinkPresentation を使うだけで情報の取得は可能ですね。

import LinkPresentation

try await run(originalURL: URL(string: "https://github.com/treastrain/tretjapannfcreader")!)

@MainActor
func run(originalURL: URL) async throws {
    let metadataProvider = LPMetadataProvider()
    let metadata = try await metadataProvider.startFetchingMetadata(for: originalURL)

    // https://github.com/treastrain/TRETJapanNFCReader
    let url = metadata.url

    // https://github.com/treastrain/tretjapannfcreader
    let originalURL = metadata.originalURL

    // "treastrain/TRETJapanNFCReader: NFC (FeliCa) Reader for iOS 13 later Core NFC / Japanese e-Money prepaid or identification cards"
    let title = metadata.title

    let icon = try await metadata.iconProvider?.loadItem(forTypeIdentifier: "public.image") as! Data
    let image = try await metadata.imageProvider?.loadItem(forTypeIdentifier: "public.image") as! Data
}
uhooi commented 2 years ago

そんなフレームワークあるのwww そしたら OSS を使わずに済むかも…。 あ、でも Linux ではつかえないのか、、GitHub Actions だと macOS で Swift 5.6 がまだ使えないのがやっかい、、、

treastrain commented 2 years ago

あ、でも Linux ではつかえないのか、、GitHub Actions だと macOS で Swift 5.6 がまだ使えないのがやっかい、、、

あっ それなのですが、すでに ios_osushi 下のリポジトリでは使えるようにしていただいております… https://github.com/ios-osushi/release-subscriptions/actions/runs/2258428022