phpBBからDiscourseに移行したところ、DiscourseのOpenGraphの実装には、Facebookが適切に画像を
表示するために重要ないくつかのタグが欠けていることがわかりました。
問題点
DiscourseのトピックをFacebookで共有すると、リンクプレビューに画像が表示されません。しかし、同じフォーラムからphpBBの投稿を共有すると、画像は正しく表示されます。
Facebookの共有デバッガー を使用すると、次のことがわかりました。
phpBBに含まれるもの:
<meta property="og:image" content="https://example.com/image.jpg">
<meta property="og:image:width" content="1024">
<meta property="og:image:height" content="768">
<meta property="og:image:type" content="image/jpeg">
Discourseに含まれるもの:
<meta property="og:image" content="https://example.com/uploads/.../image.JPG" />
デバッガーは画像を正しく表示し、HTTP 200を返しますが、Facebookはディメンションとタイプのメタデータがないと実際の共有プレビューに画像を表示しません。
なぜこれが重要なのか
OpenGraphプロトコル仕様 によると、
og:imageタグには、og:image:width、og:image:height、og:image:typeなど、いくつかのオプションの構造化プロパティがあります。
これらは技術的にはオプションですが、Facebookのクローラーは、信頼性の高い画像表示のためにこれらを要求するか、強く優先するようです。これはさまざまな情報源で文書化されており、すべてのDiscourseコミュニティのソーシャルメディア共有に影響を与えます。
提案される解決策
Discourseは、og:imageが存在するたびに、次の3つの追加のメタタグを自動的に追加する必要があります。
og:image:width - 画像の実際のピクセル幅
og:image:height - 画像の実際のピクセル高さ
og:image:type - MIMEタイプ(image/jpeg、image/pngなど)
Discourseはすでに画像を処理および最適化しているため、この情報にアクセスでき、OpenGraph出力に簡単に追加できます。
影響
これにより、すべてのDiscourseサイトのソーシャルメディア共有が改善され、共有されたリンクが視覚的に魅力的になり、DiscourseのコンテンツがFacebookやLinkedInなどのOpenGraphデータを消費するプラットフォームで共有されたときのエンゲージメントが高まります。
追加のコンテキスト
「いいね!」 6
ご報告ありがとうございます @shortmort37 これは以下で修正されます
main ← og-image-dimensions
opened 06:19PM - 16 Feb 26 UTC
Facebook's crawler requires image dimension metadata to reliably display image p… reviews when Discourse links are shared. Currently, we only emit `og:image` without the structured dimension properties, which causes Facebook (and other consumers) to skip the image in share previews.
This adds `og:image:width` and `og:image:height` meta tags for topic pages by exposing the image upload's dimensions through TopicView and passing them to `crawlable_meta_data`. The dimensions are only emitted when both width and height are available on the upload record.
https://meta.discourse.org/t/395484
「いいね!」 6
これに対応していただきありがとうございます!
しかし、なぜ og:image:type が含まれないのか教えていただけますか?phpBB は含んでいます。
ダン
「いいね!」 3
specs を読み間違えて、オプションだと思ったからです… しかし、画像の幅と高さもそうなので、それらを追加しない理由も見当たりません。
main ← fix/og-image-type
opened 11:34PM - 16 Feb 26 UTC
Follow-up to #37849 which added og:image:width and og:image:height. This adds th… e og:image:type structured property as well, providing the image MIME type (e.g. image/jpeg, image/png) derived from the upload's extension via MiniMime.
Also adds image_width, image_height, and image_type helper methods to TopicView so views don't have to reach into the upload directly, and reformats crawlable_meta_data calls in views to one argument per line for readability.
https://meta.discourse.org/t/395484
「いいね!」 6
最新のDiscourseアップデートで、Facebookとの統合が非常にうまくいっています。本当にありがとうございます!
-Dan
「いいね!」 4
もっと多くの称賛を送りたいと思います。最近、David Taylor氏の素晴らしい「Topic List Thumbnails」テーマコンポーネントをデプロイしました。トピックにサムネイルを生成できること、さらに「|thumbnail」タグを画像宣言の最後に追加することで、サムネイルを生成する画像を選択 できることは素晴らしいです。
基盤となるアーキテクチャがこのタグをog:imageとテーマコンポーネントの両方に利用しているからかもしれませんが、サムネイルを変更すると、OpenGraphプロパティのog:imageも変更され、その結果Facebookでの表示も変わることを発見して感激しました。一石二鳥、といったところでしょうか!
素晴らしい出来栄えです!
Dan