FIX: use correct URL in schema markup for post images. (#13847)

Currently, it wrongly adds Discourse base URL in prefix even for CDN URLs.
This commit is contained in:
Vinoth Kannan 2021-07-26 21:39:51 +05:30 committed by GitHub
parent e1d2b67178
commit 5a93893b08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 2 deletions

View File

@ -1087,7 +1087,8 @@ class Post < ActiveRecord::Base
end
def image_url
image_upload&.url
raw_url = image_upload&.url
UrlHelper.cook_url(raw_url, secure: image_upload&.secure?, local: true) if raw_url
end
private

View File

@ -62,7 +62,7 @@
<link itemprop="mainEntityOfPage" href="<%= post.topic.url %>">
<% if post.image_url %>
<link itemprop="image" href="<%= Discourse.base_url %><%= post.image_url %>">
<link itemprop="image" href="<%= post.image_url %>">
<% end %>
<span class="crawler-post-infos">

View File

@ -2438,6 +2438,17 @@ RSpec.describe TopicsController do
body = response.body
expect(body).to have_tag(:meta, with: { name: 'description', content: '[image_description]' })
end
it "uses image cdn url for schema markup" do
set_cdn_url("http://cdn.localhost")
post = Fabricate(:post_with_uploaded_image)
cpp = CookedPostProcessor.new(post).update_post_image
get post.topic.url
body = response.body
expect(body).to have_tag(:link, with: { itemprop: 'image', href: post.image_url })
end
end
end