mirror of
https://github.com/discourse/discourse.git
synced 2025-03-24 04:45:34 +08:00
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:
parent
e1d2b67178
commit
5a93893b08
@ -1087,7 +1087,8 @@ class Post < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def image_url
|
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
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -62,7 +62,7 @@
|
|||||||
<link itemprop="mainEntityOfPage" href="<%= post.topic.url %>">
|
<link itemprop="mainEntityOfPage" href="<%= post.topic.url %>">
|
||||||
|
|
||||||
<% if post.image_url %>
|
<% if post.image_url %>
|
||||||
<link itemprop="image" href="<%= Discourse.base_url %><%= post.image_url %>">
|
<link itemprop="image" href="<%= post.image_url %>">
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<span class="crawler-post-infos">
|
<span class="crawler-post-infos">
|
||||||
|
@ -2438,6 +2438,17 @@ RSpec.describe TopicsController do
|
|||||||
body = response.body
|
body = response.body
|
||||||
expect(body).to have_tag(:meta, with: { name: 'description', content: '[image_description]' })
|
expect(body).to have_tag(:meta, with: { name: 'description', content: '[image_description]' })
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user