FEATURE: include most popular tag in page title for webcrawlers of tagged uncategorized topics

This commit is contained in:
Neil Lalonde 2017-02-07 16:55:42 -05:00
parent a5dfcddc6c
commit 5a8bbe663a
2 changed files with 74 additions and 2 deletions

View File

@ -142,8 +142,12 @@ class TopicView
def page_title
title = @topic.title
if SiteSetting.topic_page_title_includes_category && @topic.category_id != SiteSetting.uncategorized_category_id && @topic.category_id && @topic.category
title += " - #{topic.category.name}"
if SiteSetting.topic_page_title_includes_category
if @topic.category_id != SiteSetting.uncategorized_category_id && @topic.category_id && @topic.category
title += " - #{@topic.category.name}"
elsif SiteSetting.tagging_enabled && @topic.tags.exists?
title += " - #{@topic.tags.order('tags.topic_count DESC').first.name}"
end
end
title
end

View File

@ -428,5 +428,73 @@ describe TopicView do
end
end
end
context "page_title" do
let(:tag1) { Fabricate(:tag) }
let(:tag2) { Fabricate(:tag, topic_count: 2) }
subject { TopicView.new(topic.id, coding_horror).page_title }
context "uncategorized topic" do
context "topic_page_title_includes_category is false" do
before { SiteSetting.topic_page_title_includes_category = false }
it { should eq(topic.title) }
end
context "topic_page_title_includes_category is true" do
before { SiteSetting.topic_page_title_includes_category = true }
it { should eq(topic.title) }
context "tagged topic" do
before { topic.tags << [tag1, tag2] }
context "tagging enabled" do
before { SiteSetting.tagging_enabled = true }
it { should start_with(topic.title) }
it { should_not include(tag1.name) }
it { should end_with(tag2.name) } # tag2 has higher topic count
end
context "tagging disabled" do
before { SiteSetting.tagging_enabled = false }
it { should start_with(topic.title) }
it { should_not include(tag1.name) }
it { should_not include(tag2.name) }
end
end
end
end
context "categorized topic" do
let(:category) { Fabricate(:category) }
before { topic.update_attributes(category_id: category.id) }
context "topic_page_title_includes_category is false" do
before { SiteSetting.topic_page_title_includes_category = false }
it { should eq(topic.title) }
end
context "topic_page_title_includes_category is true" do
before { SiteSetting.topic_page_title_includes_category = true }
it { should start_with(topic.title) }
it { should end_with(category.name) }
context "tagged topic" do
before do
SiteSetting.tagging_enabled = true
topic.tags << [tag1, tag2]
end
it { should start_with(topic.title) }
it { should end_with(category.name) }
it { should_not include(tag1.name) }
it { should_not include(tag2.name) }
end
end
end
end
end