mirror of
https://github.com/discourse/discourse.git
synced 2026-08-02 09:29:37 -05:00
FIX: Use correct subcategory subfolder path in crawler (#34250)
Many moons ago there was a [fix](https://github.com/discourse/discourse/pull/24595) to category urls in crawler view for a topic, due to subfolder. The old fix solved subfolders, but fumbled subcategories. This fix caters for both, such that subcategory links won't use its parent's URL.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
<div class="topic-category" itemscope itemtype="http://schema.org/BreadcrumbList">
|
||||
<% @breadcrumbs.each_with_index do |c, i| %>
|
||||
<span itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
|
||||
<a href="<%= @topic_view.topic.category.url %>" class="badge-wrapper bullet" itemprop="item">
|
||||
<a href="<%= c[:url] %>" class="badge-wrapper bullet" itemprop="item">
|
||||
<span class='badge-category-bg' style='background-color: #<%= c[:color] %>'></span>
|
||||
<span class='badge-category clear-badge'>
|
||||
<span class='category-name' itemprop='name'><%= c[:name] %></span>
|
||||
|
||||
@@ -5639,6 +5639,27 @@ RSpec.describe TopicsController do
|
||||
get "#{topic.relative_url}/2"
|
||||
end
|
||||
|
||||
it "adds breadcrumbs to the correct subcategory and category url in subfolder" do
|
||||
set_subfolder "/subpath"
|
||||
|
||||
subcategory = Fabricate(:category, parent_category_id: category.id)
|
||||
topic.update!(category: subcategory)
|
||||
|
||||
get "/t/#{topic.slug}/#{topic.id}",
|
||||
env: {
|
||||
"HTTP_USER_AGENT" => "Mozilla/5.0 ...",
|
||||
"HTTP_VIA" => "HTTP/1.0 web.archive.org",
|
||||
}
|
||||
expect(response.body).to have_tag(
|
||||
"a",
|
||||
with: {
|
||||
href: subcategory.url,
|
||||
},
|
||||
text: subcategory.name,
|
||||
)
|
||||
expect(response.body).to have_tag("a", with: { href: category.url }, text: category.name)
|
||||
end
|
||||
|
||||
context "with canonical_url" do
|
||||
fab!(:topic_embed) { Fabricate(:topic_embed, embed_url: "https://markvanlan.com") }
|
||||
let!(:user_agent) do
|
||||
|
||||
@@ -6,20 +6,6 @@ RSpec.describe "topics/show.html.erb" do
|
||||
fab!(:category)
|
||||
fab!(:topic) { Fabricate(:topic, category: category) }
|
||||
|
||||
it "uses subfolder-safe category url" do
|
||||
set_subfolder "/subpath"
|
||||
topic_view = OpenStruct.new(topic: topic, posts: [], crawler_posts: [])
|
||||
topic_view.stubs(:summary).returns("")
|
||||
view.stubs(:crawler_layout?).returns(false)
|
||||
assign(:topic_view, topic_view)
|
||||
assign(:breadcrumbs, [{ name: category.name, color: category.color }])
|
||||
assign(:tags, [])
|
||||
|
||||
render template: "topics/show", formats: [:html]
|
||||
|
||||
assert_select "a[href='/subpath/c/#{category.slug}/#{category.id}']"
|
||||
end
|
||||
|
||||
it "add nofollow to RSS alternate link for topic" do
|
||||
topic_view = OpenStruct.new(topic: topic, posts: [], crawler_posts: [])
|
||||
topic_view.stubs(:summary).returns("")
|
||||
|
||||
Reference in New Issue
Block a user