mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 09:42:02 +08:00
FEATURE: Add page number to page titles for crawlers (#26367)
At the moment, all topic `?page=` views are served with exactly identical page titles. If you search for something which is mentioned many times in the same Discourse topic, this makes for some very hard-to-understand search results! All the result titles are exactly the same, with no indication of why there are multiple results showing. This commit adds a `- Page #` suffix to the titles in this situation. This lines up with our existing strategy for topic-list pagination.
This commit is contained in:
parent
3329484e2d
commit
a8d20f92fb
|
@ -245,7 +245,10 @@ class TopicView
|
|||
else
|
||||
title += I18n.t("inline_oneboxer.topic_page_title_post_number", post_number: @post_number)
|
||||
end
|
||||
elsif @page > 1
|
||||
title += " - #{I18n.t("page_num", num: @page)}"
|
||||
end
|
||||
|
||||
if SiteSetting.topic_page_title_includes_category
|
||||
if @topic.category_id != SiteSetting.uncategorized_category_id && @topic.category_id &&
|
||||
@topic.category
|
||||
|
|
|
@ -797,6 +797,18 @@ RSpec.describe TopicView do
|
|||
end
|
||||
end
|
||||
|
||||
context "when a page number is specified" do
|
||||
it "does not include the page number for first page" do
|
||||
title = TopicView.new(topic.id, admin, page: 1).page_title
|
||||
expect(title).to eq("#{topic.title}")
|
||||
end
|
||||
|
||||
it "includes page number for subsequent pages" do
|
||||
title = TopicView.new(topic.id, admin, page: 2).page_title
|
||||
expect(title).to eq("#{topic.title} - #{I18n.t("page_num", num: 2)}")
|
||||
end
|
||||
end
|
||||
|
||||
context "with uncategorized topic" do
|
||||
context "when topic_page_title_includes_category is false" do
|
||||
before { SiteSetting.topic_page_title_includes_category = false }
|
||||
|
|
Loading…
Reference in New Issue
Block a user