Fix #5360: Use OpenGraph's og:image metadata for posts.

* Add og:image:width, og:image:height, and og:image:type tags.
* Use og:video tags for videos.
* Use 720x720 instead of 150x150 preview images for videos.
* Add duration tag to JSON-LD data for videos.
* Add OpenGraph tags to media assets show page.
* Respect Twitter max image size limits.
* Don't include OpenGraph image tags when someone shares a plain https://danbooru.donmai.us link
  with no tag search. This caused random potentially NSFW images to be shown when someone shared a
  https://danbooru.donmai.us link on social media, which could be cached for long periods of time.
This commit is contained in:
evazion
2022-12-02 00:59:23 -06:00
parent ca0a4af455
commit e11cd288b9
7 changed files with 100 additions and 50 deletions

View File

@@ -237,6 +237,10 @@
<% page_title(@post_set.page_title) %>
<% meta_description @post_set.meta_description %>
<% atom_feed_tag "Posts: #{@post_set.page_title}", posts_url(tags: @post_set.tag_string, format: :atom) %>
<% if @post_set.best_post.present? %>
<%= render OpenGraphComponent.new(media_asset: @post_set.best_post.media_asset, current_user: CurrentUser.user) %>
<% end %>
<% end %>
<% if params[:tags].blank? && @post_set.current_page == 1 %>
@@ -250,10 +254,4 @@
<% if @post_set.has_explicit? %>
<meta name="rating" content="adult">
<% end %>
<% if @post_set.best_post.present? %>
<%= tag.meta property: "og:image", content: @post_set.best_post.open_graph_image_url %>
<%= tag.meta name: "twitter:image", content: @post_set.best_post.open_graph_image_url %>
<%= tag.meta name: "twitter:card", content: "summary_large_image" %>
<% end %>
<% end %>

View File

@@ -393,21 +393,7 @@
<meta name="post-id" content="<%= @post.id %>">
<meta name="post-has-embedded-notes" content="<%= @post.has_embedded_notes? %>">
<% if policy(@post).visible? %>
<%= tag.meta property: "og:image", content: @post.open_graph_image_url %>
<% if @post.is_video? %>
<%= json_ld_video_data(@post) %>
<% end %>
<% end %>
<% if @post.twitter_card_supported? %>
<meta name="twitter:card" content="summary_large_image">
<% if policy(@post).visible? %>
<%= tag.meta name: "twitter:image", content: @post.open_graph_image_url %>
<% end %>
<% end %>
<%= render OpenGraphComponent.new(media_asset: @post.media_asset, current_user: CurrentUser.user) %>
<% if @post.rating == "e" %>
<meta name="rating" content="adult">