FEATURE: Add embed_set_canonical_url setting (#9134)

This commit is contained in:
Mark VanLandingham 2020-03-09 09:31:24 -05:00 committed by GitHub
parent f1bb1db354
commit 174764be25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 0 deletions

View File

@ -2057,6 +2057,7 @@ en:
embed_any_origin: "Allow embeddable content regardless of origin. This is required for mobile apps with static HTML."
embed_topics_list: "Support HTML embedding of topics lists"
embed_set_canonical_url: "Set the canonical URL for embeded topics to the embeded content's URL."
embed_truncate: "Truncate the embedded posts."
embed_support_markdown: "Support Markdown formatting for embedded posts."
embed_whitelist_selector: "A comma separated list of CSS elements that are allowed in embeds."

View File

@ -880,6 +880,7 @@ posting:
- code-fences
embed_any_origin: false
embed_topics_list: false
embed_set_canonical_url: false
embed_truncate:
default: true
embed_support_markdown:

View File

@ -113,6 +113,10 @@ class TopicView
end
def canonical_path
if SiteSetting.embed_set_canonical_url
topic_embed = topic.topic_embed
return topic_embed.embed_url if topic_embed
end
path = relative_url.dup
path <<
if @page > 1

View File

@ -3072,6 +3072,22 @@ RSpec.describe TopicsController do
expect(body).to include('<link rel="prev" href="' + topic.relative_url + "?page=2")
end
context "canonical_url" do
fab!(:topic_embed) { Fabricate(:topic_embed, embed_url: "https://markvanlan.com") }
let(:user_agent) { "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" }
it "set to topic.url when embed_set_canonical_url is false" do
get topic_embed.topic.url, env: { "HTTP_USER_AGENT" => user_agent }
expect(response.body).to include('<link rel="canonical" href="' + topic_embed.topic.url)
end
it "set to topic_embed.embed_url when embed_set_canonical_url is true" do
SiteSetting.embed_set_canonical_url = true
get topic_embed.topic.url, env: { "HTTP_USER_AGENT" => user_agent }
expect(response.body).to include('<link rel="canonical" href="' + topic_embed.embed_url)
end
end
context "wayback machine" do
it "renders crawler layout" do
get topic.url, env: { "HTTP_USER_AGENT" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36", "HTTP_VIA" => "HTTP/1.0 web.archive.org (Wayback Save Page)" }