From 28bb9e11f409744b26c74584ebeb8a062f7563e2 Mon Sep 17 00:00:00 2001 From: Ayke Halder Date: Wed, 9 Mar 2022 06:34:02 +0100 Subject: [PATCH] FEATURE: add nofollow to RSS alternate link in topics and categories (#16013) * FEATURE: add nofollow to RSS alternate link in topics and categories * Rspec tests for category and topic view: add nofollow to RSS alternate link --- app/views/list/list.erb | 2 +- app/views/topics/show.html.erb | 2 +- spec/views/list/list.erb_spec.rb | 18 ++++++++++++++++++ spec/views/topics/show.html.erb_spec.rb | 23 +++++++++++++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 spec/views/list/list.erb_spec.rb create mode 100644 spec/views/topics/show.html.erb_spec.rb diff --git a/app/views/list/list.erb b/app/views/list/list.erb index 4f53cd307b..63a9b91c0c 100644 --- a/app/views/list/list.erb +++ b/app/views/list/list.erb @@ -142,7 +142,7 @@ <% if @category %> <% content_for :head do %> - <%= auto_discovery_link_tag(:rss, { action: :category_feed }, title: t('rss_topics_in_category', category: @category.name)) %> + <%= auto_discovery_link_tag(:rss, { action: :category_feed }, rel: 'alternate nofollow', title: t('rss_topics_in_category', category: @category.name)) %> <%= raw crawlable_meta_data(title: @category.name, description: @category.description, image: @category.uploaded_logo&.url.presence) %> <% end %> <% elsif @tag_id %> diff --git a/app/views/topics/show.html.erb b/app/views/topics/show.html.erb index b69bacd64b..8dd43f979a 100644 --- a/app/views/topics/show.html.erb +++ b/app/views/topics/show.html.erb @@ -131,7 +131,7 @@ <% end %> <% content_for :head do %> - <%= auto_discovery_link_tag(@topic_view, {action: :feed, slug: @topic_view.topic.slug, topic_id: @topic_view.topic.id}, title: t('rss_posts_in_topic', topic: @topic_view.title), type: 'application/rss+xml') %> + <%= auto_discovery_link_tag(@topic_view, {action: :feed, slug: @topic_view.topic.slug, topic_id: @topic_view.topic.id}, rel: 'alternate nofollow', title: t('rss_posts_in_topic', topic: @topic_view.title), type: 'application/rss+xml') %> <%= raw crawlable_meta_data(title: @topic_view.title, description: @topic_view.summary(strip_images: true), image: @topic_view.image_url, read_time: @topic_view.read_time, like_count: @topic_view.like_count, ignore_canonical: true, published_time: @topic_view.published_time) %> <% if @topic_view.prev_page || @topic_view.next_page %> diff --git a/spec/views/list/list.erb_spec.rb b/spec/views/list/list.erb_spec.rb new file mode 100644 index 0000000000..d411de6833 --- /dev/null +++ b/spec/views/list/list.erb_spec.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require "rails_helper" + +describe "list/list.erb" do + fab!(:category) { Fabricate(:category) } + + it "add nofollow to RSS alternate link for category" do + view.stubs(:include_crawler_content?).returns(false) + view.stubs(:url_for).returns('https://www.example.com/test.rss') + view.instance_variable_set("@rss", false) + view.instance_variable_set("@category", category) + render template: 'list/list', formats: [] + + expect(view.content_for(:head)).to match(//) + end + +end diff --git a/spec/views/topics/show.html.erb_spec.rb b/spec/views/topics/show.html.erb_spec.rb new file mode 100644 index 0000000000..a311c50010 --- /dev/null +++ b/spec/views/topics/show.html.erb_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require "rails_helper" +require "ostruct" + +describe "topics/show.html.erb" do + fab!(:topic) { Fabricate(:topic) } + + it "add nofollow to RSS alternate link for topic" do + topic_view = OpenStruct.new( + topic: topic, + posts: [] + ) + topic_view.stubs(:summary).returns('') + view.stubs(:crawler_layout?).returns(false) + view.stubs(:url_for).returns('https://www.example.com/test.rss') + view.instance_variable_set("@topic_view", topic_view) + render template: 'topics/show', formats: [:html] + + expect(view.content_for(:head)).to match(//) + end + +end