Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Add page number to page titles for crawlers (#26367)

David Taylora8d20f92fb7a
diff --git a/lib/topic_view.rb b/lib/topic_view.rb
index d30a7c3a7a1..b59ba0f1543 100644
--- a/lib/topic_view.rb
+++ b/lib/topic_view.rb
@@ -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
diff --git a/spec/lib/topic_view_spec.rb b/spec/lib/topic_view_spec.rb
index 0ddff7849ed..cdc67944f55 100644
--- a/spec/lib/topic_view_spec.rb
+++ b/spec/lib/topic_view_spec.rb
@@ -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 }