no_follow_external_links 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -2
- data/config/initializers/no_follow_external_links.rb +18 -4
- data/lib/no_follow_external_links.rb +9 -1
- data/lib/no_follow_external_links/configuration.rb +9 -0
- data/lib/no_follow_external_links/version.rb +1 -1
- data/spec/dummy/app/views/cars/index.html.erb +1 -0
- data/spec/feature/external_links_with_exception_spec.rb +22 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7650233c1d858b784e9ed8ca97b3cbec2cc2ee8
|
4
|
+
data.tar.gz: ee78a404b057dfc275e3504cbdaf3e2070e15d79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3295784e00e2ef54acdea54684fe4369c5166574add9c101289fe547e63a1d1f0bb66f50ca6a94221cd98177d8975f6cfe5f401002c73a6dc92731056f9c684c
|
7
|
+
data.tar.gz: e6a6c407bf1398c52e4b4c9546e8bebe245a3a5ca40656de9c691ceef11f726544f5007ea983f1963b8d8e46c53007aa152e9742bcb9f78a200d20a927e3fa0f
|
data/README.md
CHANGED
@@ -1,8 +1,16 @@
|
|
1
1
|
# NoFollowExternalLinks
|
2
|
-
|
2
|
+
Links that point to external urls are recommended to include a rel=nofollow property to make sure the crawler bots do not follow the content of external resources as your own.
|
3
|
+
This plugin makes it easy to implement that for all existing links on a Rails application.
|
3
4
|
|
4
5
|
## Usage
|
5
|
-
|
6
|
+
This plugin will automatically add a nofollow rel property to all the external links you create using Rails `link_to` method
|
7
|
+
If you need to add an exception for instance for your own personal blog within a subdomain just add an intializer with the following:
|
8
|
+
|
9
|
+
```
|
10
|
+
NoFollowExternalLinks.configure do |config|
|
11
|
+
config.excluded_urls = %w{https://blog.mydomain.com/}
|
12
|
+
end
|
13
|
+
```
|
6
14
|
|
7
15
|
## Installation
|
8
16
|
Add this line to your application's Gemfile:
|
@@ -1,15 +1,29 @@
|
|
1
|
+
require 'byebug'
|
2
|
+
|
3
|
+
NoFollowExternalLinks.configure do |config|
|
4
|
+
config.excluded_urls = []
|
5
|
+
end
|
6
|
+
|
1
7
|
Rails.configuration.to_prepare do
|
2
8
|
ApplicationHelper.class_eval do
|
3
9
|
def link_to(name, options = {}, html_options = {})
|
4
|
-
html_options.merge!(rel: :nofollow)
|
10
|
+
html_options.merge!(rel: :nofollow) if add_nofollow? options
|
5
11
|
super(name, options, html_options)
|
6
12
|
end
|
7
13
|
|
8
14
|
private
|
9
15
|
|
10
|
-
def
|
11
|
-
|
12
|
-
|
16
|
+
def add_nofollow?(url)
|
17
|
+
external_url?(url) && excluded_url?(url)
|
18
|
+
end
|
19
|
+
|
20
|
+
def excluded_url?(url)
|
21
|
+
!NoFollowExternalLinks.configuration.excluded_urls.include?(url)
|
22
|
+
end
|
23
|
+
|
24
|
+
def external_url?(url)
|
25
|
+
return false unless self.respond_to? :root_url
|
26
|
+
url.try(:first) != '/' && !url.try(:include?, root_url)
|
13
27
|
end
|
14
28
|
end
|
15
29
|
end
|
@@ -1,5 +1,13 @@
|
|
1
1
|
require "no_follow_external_links/engine"
|
2
|
+
require "no_follow_external_links/configuration"
|
2
3
|
|
3
4
|
module NoFollowExternalLinks
|
4
|
-
|
5
|
+
class << self
|
6
|
+
attr_accessor :configuration
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.configure
|
10
|
+
self.configuration ||= Configuration.new
|
11
|
+
yield(configuration)
|
12
|
+
end
|
5
13
|
end
|
@@ -1,3 +1,4 @@
|
|
1
1
|
<%=link_to 'Internal cars', car_path('example'), id: 'car_internal_link'%>
|
2
2
|
<%=link_to 'Internal cars full url', car_url('example'), id: 'car_internal_url_ink'%>
|
3
3
|
<%=link_to 'External cars', 'https://www.cars.com/', id: 'car_external_link'%>
|
4
|
+
<%=link_to 'External cars but excluded', 'https://www.mycars.com/', id: 'car_external_excluded_link'%>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
feature 'Add no follow attribute to external links' do
|
4
|
+
before do
|
5
|
+
NoFollowExternalLinks.configure do |config|
|
6
|
+
config.excluded_urls = %w{https://www.mycars.com/}
|
7
|
+
end
|
8
|
+
visit root_path
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should show the external link' do
|
12
|
+
expect(page).to have_selector :link_or_button, 'External cars but excluded'
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'adds a nofollow rel to external link links' do
|
16
|
+
expect(find('a#car_external_link')['rel']).to eq('nofollow')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'does not add a nofollow rel to external excluded links' do
|
20
|
+
expect(find('a#car_external_excluded_link')['rel']).not_to be
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: no_follow_external_links
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pablo Gonzaga
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -157,6 +157,7 @@ files:
|
|
157
157
|
- config/initializers/no_follow_external_links.rb
|
158
158
|
- config/routes.rb
|
159
159
|
- lib/no_follow_external_links.rb
|
160
|
+
- lib/no_follow_external_links/configuration.rb
|
160
161
|
- lib/no_follow_external_links/engine.rb
|
161
162
|
- lib/no_follow_external_links/version.rb
|
162
163
|
- lib/tasks/no_follow_external_links_tasks.rake
|
@@ -263,6 +264,7 @@ files:
|
|
263
264
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/x7/x7PYh8DJvPykcEqpVab2vcY9-GFz-3cqtoMlRAu94Uc.cache
|
264
265
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/yT/yTBgOVdriipCfu0f-gBdtxY7YwyFmTyw8XmeYbxRYRI.cache
|
265
266
|
- spec/feature/external_links_spec.rb
|
267
|
+
- spec/feature/external_links_with_exception_spec.rb
|
266
268
|
- spec/feature/internal_links_spec.rb
|
267
269
|
- spec/spec_helper.rb
|
268
270
|
homepage: https://github.com/pgonzaga2012/no_follow_external_links
|
@@ -393,5 +395,6 @@ test_files:
|
|
393
395
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/yT/yTBgOVdriipCfu0f-gBdtxY7YwyFmTyw8XmeYbxRYRI.cache
|
394
396
|
- spec/dummy/tmp/cache/assets/sprockets/v3.0/Zl/Zlabymek1OchThl--EYnug-w71BxsUbsswgwbbi3X4w.cache
|
395
397
|
- spec/feature/external_links_spec.rb
|
398
|
+
- spec/feature/external_links_with_exception_spec.rb
|
396
399
|
- spec/feature/internal_links_spec.rb
|
397
400
|
- spec/spec_helper.rb
|